I’m trying to get the Day of the week from a Nullable DateTime and then Joining on a list of days.
My solution was to convert it to a DateTime first, but Linq to Entities doesn’t like it.
LIST is an IEnumerable<string>
suggestions?
var result = from X in model.X
where X.StartDate.HasValue
join item in LIST on
Convert.ToDateTime(X.StartDate).DayOfWeek.ToString() equals item
select X;
Converting to a methods chain is no help:
var result = model.X.Where(x => x.StartDate.HasValue).Join(LIST,x => Convert.ToDateTime(x.StartDate).DayOfWeek.ToString(), item => item, (x, item) => x);
.ToString() is not supported by Linq-To-Entities, as are a number of other extension methods.
The short (and probably inaccurate to some degree) reason is that the .ToString() in the context above is sent to Sql Server to run in a query. Sql Server has no idea what .ToString() is, and so it fails when Sql Server’s query parser tries to execute it.
also, FYI
http://msdn.microsoft.com/en-us/library/bb738550.aspx