I have a Query
SpecialAttributes is a IEnumerable
q = from c in q
let x = c.SpecialAttributes.Where(a => a.Attribute.Id == id)
.Select(z => z.AttribValue).SingleOrDefault()
orderby Convert.ToDateTime(x)
select c;
I need to execute sql query at once.
But in this case each SingleOrDefault() will be executed separately of main query.
If count of fetching results will be 100 – SingleOrDefault() will be executed 100 times.
How do it in one query, like FutureSingleOrDefault() ?
Assuming you won’t have attributes with the same id in your special attributes collection and that your “SpecialAttribute” class has a reference to the parent object, this may work:
I don’t know if EF will parse the Convert.ToDateTime() to a proper t-sql statement. If not, you could do it in memory (if the collection is not huge):