Does anyone know of a definitive list of LINQ to SQL query limitations that are not trapped at compile time, along with (where possible) workarounds for the limitations?
I had exactly this issue with DateTimes, and found that currently the following workaround works for me, but I realise that with larger result sets, it could get to be an issue as the processing is now in my app rather than on the database:
BlogPosts post = (from blogs in blogPosts
where blogs.PostPath == path
select blogs)
.ToList()
.Where(blogs => blogs.Published.Date == publishedDate.Date)
.SingleOrDefault();
Note the ".ToList()" in the middle - this casts it to a normal IEnumerable and allows me to use the usual properties I'd expect.
One thing that still confuses me slightly however is the fact that this is legal in EF:
BlogPosts posts = from blogs in blogPosts
where !blogs.IsDraft
&& blogs.Published.Year == year
&& blogs.Published.Month == month
orderby blogs.Published descending
select blogs
So, I can call ".Year" or ".Month" on a DateTime, but not ".Date" - I guess it comes down to types.