ef AddDays报错

ef func写法,在语句中不能使用adddays方法

where(u=>u.date>datetime.now.AddDays(1));
这样写就是不行
可以改为:
where(u=>System.Data.Objects.EntityFunctions.DiffDays(datetime.now, u.Date)>0);

下面是我的一个案例,虽然到了最后都没有实现功能!


 

 

 

 public List<ContractBudget> ListRemindPaymentForAutoSMS()
        {
            using (var dbContext = new FMDbContext())
            {
                IQueryable<ContractBudget> ShowList = dbContext.ContractBudget.Include("CommercialTenant").Include("Contract").Include("Contract.Staff").Include("Contract.Bill").Include("Contract.Bill.Branch").Include("Contract.Bill.Order").Include("Contract.Bill.Order.Room");
                //开通短信自动发送有效、有余额商户id-list
                List<int> listcommerid = ConfigManager.ListCommercialTenantForRemindPaymentAutoSMS();
                Dictionary<int, int> dic = new Dictionary<int, int>();
                //(from u in dbContext.ContractBudget where dic.Keys.Contains(u.CommercialtenantID) select u into g new {value = dic[]} );
                //通过list取数据--取出支付日期在提醒器内的商户的出房合同预算//催缴期内
                var now = DateTime.Now.Date;ShowList = ShowList.Where(u => dic.Keys.Contains(u.ID) && now >= u.Date.AddDays(Convert.ToDouble(dic.Where(d => d.Key == u.ID).First().Key)).Date && now <= u.Date);
                //未缴费、房租
                ShowList = ShowList.Where(u => u.CheckStatus == (int)EnumContractBudgetCheckStatus.WSH && u.Type == (int)EnumContractBudgetType.FZ);
                //预算没有提醒过
                ShowList = ShowList.Where(u => u.isAutoSMS == 0);
                return ShowList.ToList();
            }
        }

这里会报错

ShowList = ShowList.Where(u => dic.Keys.Contains(u.ID) && now >= u.Date.AddDays(Convert.ToDouble(dic.Where(d => d.Key == u.ID).First().Key)).Date && now <= u.Date);

        public List<ContractBudget> ListRemindPaymentForAutoSMS()
        {
            using (var dbContext = new FMDbContext())
            {
                IQueryable<ContractBudget> ShowList = dbContext.ContractBudget.Include("CommercialTenant").Include("Contract").Include("Contract.Staff").Include("Contract.Bill").Include("Contract.Bill.Branch").Include("Contract.Bill.Order").Include("Contract.Bill.Order.Room");
                //开通短信自动发送有效、有余额商户id-list
                List<int> listcommerid = ConfigManager.ListCommercialTenantForRemindPaymentAutoSMS();
                Dictionary<int, int> dic = new Dictionary<int, int>();//通过list取数据--取出支付日期在提醒器内的商户的出房合同预算//催缴期内
                var now = DateTime.Now.Date;
                ShowList = ShowList.Where(u =>  now <= u.Date && System.Data.Objects.EntityFunctions.DiffDays(now, u.Date) < dic.Where(d => d.Key == u.ID).First().Value);
                ShowList = ShowList.Where(u => u.CheckStatus == (int)EnumContractBudgetCheckStatus.WSH && u.Type == (int)EnumContractBudgetType.FZ);
                //预算没有提醒过
                ShowList = ShowList.Where(u => u.isAutoSMS == 0);
                return ShowList.ToList();
            }
        }

也就是adddays做的判断改成(datetime-datetime).days>number

但是我写的语句还是不行,建议不采用dic的形式!

 

转载于:https://www.cnblogs.com/zhaokunbokeyuan256/p/7562548.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值