C# 实体数据源日期时间,其中参数
我有一个EDS,它查看带有日期时间的事件列表,我想要一个where参数,用于查看某一天的所有事件 我想要一个看起来像这样的:C# 实体数据源日期时间,其中参数,c#,asp.net,entity-framework,C#,Asp.net,Entity Framework,我有一个EDS,它查看带有日期时间的事件列表,我想要一个where参数,用于查看某一天的所有事件 我想要一个看起来像这样的: Where="it.EventStartDateTime = @testDate" 但是由于EventStartDateTime包含一个时间,而testDate只是一个日期,所以它们永远不会匹配 我试过了 Where="it.EventStartDateTime.Date = @testDate" 但是我得到一个关于Date不在模式中的错误(?) 我试过了 Where
Where="it.EventStartDateTime = @testDate"
但是由于EventStartDateTime
包含一个时间,而testDate
只是一个日期,所以它们永远不会匹配
我试过了
Where="it.EventStartDateTime.Date = @testDate"
但是我得到一个关于Date
不在模式中的错误(?)
我试过了
Where="it.EventStartDateTime Like @testDate"
这也不管用
有人知道怎么做吗
提前感谢我们通过以下方式解决了这个问题:
eventsEDS.Where = "it.EventStartDateTime >= @cDate && it.EventStartDateTime < @cDate1 ";
eventsEDS.WhereParameters.Add("cDate", TypeCode.DateTime, eventStartDateTime.ToShortDateString());
eventsEDS.WhereParameters.Add("cDate1", TypeCode.DateTime, eventStartDateTime.AddDays(1).ToShortDateString());
eventsEDS.Where=“it.EventStartDateTime>=@cDate&&it.EventStartDateTime<@cDate1”;
eventsEDS.WhereParameters.Add(“cDate”,TypeCode.DateTime,eventStartDateTime.ToShortDateString());
eventsEDS.WhereParameters.Add(“cDate1”,TypeCode.DateTime,eventStartDateTime.AddDays(1.ToSortDateString());
虽然不理想,但效果很好