I'm new in Linq and I'm trying to optimize some queries and I don't have any idea if it is possible for this queries:
var cSRez = (from l in MyTable
where l.Name == "dcc" && l.Service == "Main"
orderby l.Time descending
select l.Value).FirstOrDefault();
var cDRez = (from l in MyTable
where l.Name == "dcc" && l.Service == "DB"
orderby l.Time descending
select l.Value).FirstOrDefault();
var dSRez = (from l in MyTable
where l.Name == "ddc" && l.Service == "Main"
orderby l.Time descending
select (long?)l.Value).FirstOrDefault();
var dDRez = (from l in MyTable
where l.Name == "ddc" && l.Service == "DB"
orderby l.Time descending
select (long?)l.Value).FirstOrDefault();
var mSRez = (from l in MyTable
where l.Name == "mc" && l.Service == "Main"
orderby l.Time descending
select l.Value).FirstOrDefault();
var mDRez = (from l in MyTable
where l.Name == "mc" && l.Service == "DB"
orderby l.Time descending
select l.Value).FirstOrDefault();
to become a single one.
I was thinking about row_number() over(partition by... (SQL) but I don't think this is the best idea for doing this.
It is possible to collapse this six separate queries into a single one?
FirstOrDefault.