ef func写法,在语句中不能使用adddays方法
where(u=>u.date>datetime.now.AddDays());
这样写就是不行
可以改为:
where(u=>System.Data.Objects.EntityFunctions.DiffDays(datetime.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>();
//(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 == );
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 == );
return ShowList.ToList();
}
}
也就是adddays做的判断改成(datetime-datetime).days>number
但是我写的语句还是不行,建议不采用dic的形式!