我正在使用我的linq查询,如下所示
var result = from m in genDB.Membership_Association
join ag in genDB.Account_Group on m.Account_Group_ID equals ag.Account_Group_ID
join s in genDB.Account_Section on m.Account_Section_ID equals s.Account_Section_ID
join p in genDB.Account_Package on m.Account_Package_ID equals p.Account_Package_ID
join pinfo in genDB.ProductInfo on m.Product_ID equals pinfo.Product_Id
where m.Control_Plan_ID == controlPlanId && m.Account_ID == accId
select new MembershipViewModel
{
GroupNumber = ag.Account_Group_Number,
SectionNumber = s.Account_Section_Number,
PackageNumber = p.Account_Package_Number,
ProductName = pinfo.Product_Name,
CreatedDate = m.Create_Date.Date,
EffectiveDate = m.Effective_Date.Value.Date,
CancelledDate = m.Cancel_Date.Value.Date,
Status = m.Status
};
在上面的查询中,它抛出异常“LINQ to Entities不支持指定的类型成员'Date'。仅支持初始值设定项,实体成员和实体导航属性。” at .Date prperty
答案 0 :(得分:1)
您需要确保仅比较两侧的日期部分。
测试用例:
4.如果是日期类型,请使用日期类型进行检查。 例如,
var query =来自db.MyTable中的e,其中e.AsOfDate< = DateTime.Now.Date选择e;
如果你尝试过,你将能够接近解决方案。
您可能需要在代码中执行以下操作:
CreatedDate.Date = m.Create_Date.Date
答案 1 :(得分:1)
您可以使用SqlFunctions.DatePart
提取要比较的DateTime的相关部分。见http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.datepart.aspx