C# Dbathmetic表达式参数必须具有数字公共类型。实体框架
我有一个MVC应用程序,我想根据我的要求从sql server数据库中获取记录。我主要有表“OfficeDetail”,其中一列是“ApprovedDate”,第二列是“ChildCount”。“Approvedate”包含用户文档的批准日期。第二个“ChildCount”包含整数值。我还在这个网站上搜索了另一个问题,但没有找到答案。我使用了两个where条件,所以我为get record编写了这段代码C# Dbathmetic表达式参数必须具有数字公共类型。实体框架,c#,entity-framework,datetime,C#,Entity Framework,Datetime,我有一个MVC应用程序,我想根据我的要求从sql server数据库中获取记录。我主要有表“OfficeDetail”,其中一列是“ApprovedDate”,第二列是“ChildCount”。“Approvedate”包含用户文档的批准日期。第二个“ChildCount”包含整数值。我还在这个网站上搜索了另一个问题,但没有找到答案。我使用了两个where条件,所以我为get record编写了这段代码 public IEnumerable<EmployeeModel> GetAl
public IEnumerable<EmployeeModel> GetAllExpired()
{
DateTime my = DateTime.Today;
DBContext = new ConsumerNomineeFormEntities();
return (from f in DBContext.OfficeDetails
where (SqlFunctions.DateDiff("second",f.Date,my.Date)>90)
where (f.ChildCount>5)
select new EmployeeModel
{
XConsumer_Id = f.ConsumerNo_,
XApproved = f.Date,
XChildCount = f.ChildCount,
XTimeSpent = (f.Date - DateTime.Today).TotalDays
}).ToList();
}
public IEnumerable GetAllExpired()
{
DateTime my=DateTime.Today;
DBContext=新的ConsumerNomineeFormEntities();
返回(来自DBContext.OfficeDetails中的f)
其中(SqlFunctions.DateDiff(“second”,f.Date,my.Date)>90)
其中(f.ChildCount>5)
选择新的EmployeeModel
{
XConsumer\u Id=f.ConsumerNo\u,
XApproved=f.日期,
XChildCount=f.ChildCount,
xtimepowned=(f.Date-DateTime.Today).TotalDays
}).ToList();
}
问题似乎是Xtimespend的计算,因为您需要使用sqlfunctions减去日期问题似乎是Xtimespend的计算,因为您需要使用sqlfunctions减去日期好的,最后我得到了,我必须做出这样的更改
DBContext = new ConsumerNomineeFormEntities();
return (from f in DBContext.OfficeDetails
where SqlFunctions.DateDiff("day", f.Date, my.Date) > 90
where f.ChildCount < 5
select new EmployeeModel
{
XConsumer_Id = f.ConsumerNo_,
XApproved = f.Date,
XChildCount = f.ChildCount,
XTimeSpent = SqlFunctions.DateDiff("day", f.Date, my.Date)
}).ToList();
DBContext=newconsumernomineeformentities();
返回(来自DBContext.OfficeDetails中的f)
其中SqlFunctions.DateDiff(“day”,f.Date,my.Date)>90
其中f.ChildCount<5
选择新的EmployeeModel
{
XConsumer\u Id=f.ConsumerNo\u,
XApproved=f.日期,
XChildCount=f.ChildCount,
xtimetowned=SqlFunctions.DateDiff(“day”,f.Date,my.Date)
}).ToList();
好的,最后我得到了,我必须做出这样的更改
DBContext = new ConsumerNomineeFormEntities();
return (from f in DBContext.OfficeDetails
where SqlFunctions.DateDiff("day", f.Date, my.Date) > 90
where f.ChildCount < 5
select new EmployeeModel
{
XConsumer_Id = f.ConsumerNo_,
XApproved = f.Date,
XChildCount = f.ChildCount,
XTimeSpent = SqlFunctions.DateDiff("day", f.Date, my.Date)
}).ToList();
DBContext=newconsumernomineeformentities();
返回(来自DBContext.OfficeDetails中的f)
其中SqlFunctions.DateDiff(“day”,f.Date,my.Date)>90
其中f.ChildCount<5
选择新的EmployeeModel
{
XConsumer\u Id=f.ConsumerNo\u,
XApproved=f.日期,
XChildCount=f.ChildCount,
xtimetowned=SqlFunctions.DateDiff(“day”,f.Date,my.Date)
}).ToList();
thnx。。但直到我有一个问题,根据我的where条件,我在表中有一个记录,批准日期为2015-08-20,childcount为3,因此该日期与今天日期之间的差异超过90天。但是我的屏幕上没有任何记录,而我有一条记录好的,但是你为什么不把这个答案标记为已解决?您的问题描述是关于异常的,并用此答案解决了。因为您的答案不是完美的解决方案。。。但我给你的学分。。。那我的呢…嗯。。但直到我有一个问题,根据我的where条件,我在表中有一个记录,批准日期为2015-08-20,childcount为3,因此该日期与今天日期之间的差异超过90天。但是我的屏幕上没有任何记录,而我有一条记录好的,但是你为什么不把这个答案标记为已解决?您的问题描述是关于异常的,并用此答案解决了。因为您的答案不是完美的解决方案。。。但我给你的学分。。。那我的呢。。。