Answer the question
In order to leave comments, you need to log in
How to correctly correlate a calculated field of an Entity Framework model?
Hello!
There is some calculated field in the Entity Framework model:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[NotMapped]
public int? WorkingTime
{ get {
var query = (from e in context.events
join a in context.actions on e.CurrEventID equals a.CurrEventID into es
from p in es.DefaultIfEmpty()
select new { UnitDate = e.ActionDate, UnitId = e.CurrEventID, HeaderID = p.HeaderID, IsDone = p.MarkerOn, Begin = e.BeginTime, End = e.EndTime })
.Where(w => w.HeaderID == this.HeaderID)
.Where(w => w.IsDone == true)
.Distinct()
.Select(s => DbFunctions.DiffMinutes(s.Begin, s.End)).Sum();
return query ?? 0;
} }
Answer the question
In order to leave comments, you need to log in
Implement as a helper?
public static class Helper{
public static int? GetWorkingTime(this MyContext context){
var query = (from e in context.events
join a in context.actions on e.CurrEventID equals a.CurrEventID into es
from p in es.DefaultIfEmpty()
select new { UnitDate = e.ActionDate, UnitId = e.CurrEventID, HeaderID = p.HeaderID, IsDone = p.MarkerOn, Begin = e.BeginTime, End = e.EndTime })
.Where(w => w.HeaderID == this.HeaderID)
.Where(w => w.IsDone == true && w.Begin<w.UnitDate && w.UnitDate<w.End )
.Distinct()
.Select(s => DbFunctions.DiffMinutes(s.Begin, s.End)).Sum();
return query ?? 0;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question