I am trying to do a LINQ to Entities query (am still very new with EF and am learning where it is diff than LinqToSQL) and am trying to do something like this:
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();
while this works in LinqPad, it doesn't in my code. The thrown exception is:
The specified type member 'Date' is not supported in LINQ to Entities.
Only initializers, entity members, and entity navigation properties are supported.
How do I do this in LinqToEF? The field in the DB is a full DateTime (with timecode) and I am trying to parse based on date only.
You cann't simple use 'app.ReleaseDate.Data', but you can:
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With