This is what I am trying to do.
data = (from t in db.Table
where ...
select new
{
Property = t.Table2.Any() ? new Nullable<DateTime>(t.Table2.OrderByDescending(x => x.DateField).FirstOrDefault().DateField) : null
});
if there is anything in table2 i want to get the most recent date if not then return null but it’s not letting me use new Nullable<>(). Also AS DateTime? does not work. This used to work in linq2sql but using EF which I have switched to it throws errors.
1 Answer