Bra*_*son 4 c# entity-framework
我正在尝试进行LINQ to Entities查询(我仍然非常熟悉EF并且我正在学习它比LinqToSQL差异化)并且我正在尝试做这样的事情:
DateTime begin = new DateTime(2011, 1, 1);
Apps = (from app in context.Instances
where app.ReleaseDate.Date == begin
select new ScalpApp
{
Image = app.Image,
PublisherName = app.PublisherName,
}).ToList();
Run Code Online (Sandbox Code Playgroud)
虽然这在LinqPad中有效,但它不在我的代码中.抛出的异常是:
Run Code Online (Sandbox Code Playgroud)The specified type member 'Date' is not supported in LINQ to Entities.仅支持初始值设定项,实体成员和实体导航属性.
我如何在LinqToEF中执行此操作?DB中的字段是完整的DateTime(带有时间码),我试图仅根据日期进行解析.
你不能简单地使用'app.ReleaseDate.Data',但你可以:
var begin = new DateTime(2011, 1, 1);
var end = begin.AddHours(24);
Apps = (from app in context.Instances
where
(app.ReleaseDate >= begin) and
(app.ReleaseDate < end)
select new ScalpApp
{
Image = app.Image,
PublisherName = app.PublisherName,
}).ToList();
Run Code Online (Sandbox Code Playgroud)