Is it possible to turn this into an entity framework query that will only query the database once?
select max(TableADate) latestTableADate, max(TableBDate) latestTableBDate
from
(
select max(a.ModifiedDate) TableADate, null TableBDate
from TableA a
union all
select null, max(b.ModifiedDate)
from TableB b
) data
The intent is to get the latest ModifiedDate from multiple tables with one sql statement so Entity Framework is not doing multiple trips to the database to get the data.
I need to know when the last time that one of the tables was updated.
Update:
I ended using DbContext.Database.SqlQuery
doing the following:
var output = db.Database.SqlQuery<DateTime>
("select data from (" +
"select 1 orderBy, max(ModifiedDate) data from TableA" +
"union all " +
"select 2, max(ModifiedDate) from TableB " +
") temp order by orderby").ToList();
data.TableADate = output[0];
data.TableBDate = output[1];