Charles Baldo
asked on
Need more efficient LINQ
I have this SQL Code and converted to the below LINQ to Entities. I generated the LINQ code but think there must be a better way. I am trying to implement a Sequence column value. The table already has an identity column and a sequence for each item
and this LINQ
SELECT MAX(COALESCE(FailureSequence, 0)) + 1 AS NextSequence
FROM FunctionalFailures
WHERE(FunctionalAnalysisId = 2);
and this LINQ
from FunctionalFailures in
(from FunctionalFailures in db.FunctionalFailures
where
FunctionalFailures.FunctionalAnalysisId == 2
select new {
Column1 = ((Int32?)FunctionalFailures.FailureSequence ?? (Int32?)0),
Dummy = "x"
})
group FunctionalFailures by new { FunctionalFailures.Dummy } into g
select new {
NextSequence = (g.Max(p => p.Column1) + 1)
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Excellent, glad to help.
ASKER
Was able to adapt to my code thanks