Wpf 如何将linq中的日期与没有datetime的实体查询进行比较 var query=\u context.POS\u ItemPriceListMaster.Where(c=>c.FromDate>=FromDate&&c.ToDate t.ItemPriceListMasterID); var query2=来自_context.POS\u ItemPriceList中的c 其中query.Contains(c.ItemPriceListMasterID) 选择c;

Wpf 如何将linq中的日期与没有datetime的实体查询进行比较 var query=\u context.POS\u ItemPriceListMaster.Where(c=>c.FromDate>=FromDate&&c.ToDate t.ItemPriceListMasterID); var query2=来自_context.POS\u ItemPriceList中的c 其中query.Contains(c.ItemPriceListMasterID) 选择c;,wpf,linq-to-entities,Wpf,Linq To Entities,我想这样做,但在查询中没有结果,尽管有起始日期为的数据 数据库中的字段是datetime我假设c.FromDate和c.ToDate是没有时间信息的日期,FromDate是有时间信息的日期 要修复查询,请从FromDate中删除时间: var query = _context.POS_ItemPriceListMaster.Where(c => c.FromDate >= FromDate && c.ToDate <= FromDate).Select(t=&

我想这样做,但在查询中没有结果,尽管有起始日期为的数据
数据库中的字段是datetime

我假设
c.FromDate
c.ToDate
是没有时间信息的日期,
FromDate
是有时间信息的日期

要修复查询,请从
FromDate
中删除时间:

 var query = _context.POS_ItemPriceListMaster.Where(c => c.FromDate >= FromDate && c.ToDate <= FromDate).Select(t=> t.ItemPriceListMasterID);
        var query2 = from c in _context.POS_ItemPriceList
                         where query.Contains(c.ItemPriceListMasterID)
                         select c;
var fromDateWithoutTime=FromDate.Date;

var query=\u context.POS\u ItemPriceListMaster .其中(c=>c.FromDate>=fromDateWithoutTime &&c.ToDate t.ItemPriceListMasterID);
我假设
c.FromDate
c.ToDate
是没有时间信息的日期,
FromDate
是有时间信息的日期

要修复查询,请从
FromDate
中删除时间:

 var query = _context.POS_ItemPriceListMaster.Where(c => c.FromDate >= FromDate && c.ToDate <= FromDate).Select(t=> t.ItemPriceListMasterID);
        var query2 = from c in _context.POS_ItemPriceList
                         where query.Contains(c.ItemPriceListMasterID)
                         select c;
var fromDateWithoutTime=FromDate.Date;

var query=\u context.POS\u ItemPriceListMaster .其中(c=>c.FromDate>=fromDateWithoutTime &&c.ToDate t.ItemPriceListMasterID);
你确定你的查询是正确的吗?条件c=>c.FromDate>=FromDate&&c.ToDate c.FromDate>=FromDate&&c.ToDate你确定你的查询是正确的吗?条件c=>c.FromDate>=FromDate&&c.ToDate var query=\u context.POS\u ItemPriceListMaster.Where(c=>EntityFunctions.TruncateTime(c.FromDate)>=FromDate.Date&&EntityFunctions.TruncateTime(c.ToDate)t.ItemPriceListMasterID);现在我用这个,但它也不是work@nadeemaamir:如果您没有由
FromDate
指定的日期的数据,则
FromDate
必须介于
FromDate
ToDate
之间,因此必须交换
=
。var query=\u context.POS\u ItemPriceListMaster.Where(c=>EntityFunctions.TruncateTime(c.FromDate)>=FromDate.Date&&EntityFunctions.TruncateTime(c.ToDate)t.ItemPriceListMasterID);现在我用这个,但它也不是work@nadeemaamir:如果您没有由
FromDate
指定的日期的数据,则
FromDate
必须介于
FromDate
ToDate
之间,因此必须交换
=