It may be simple, but I was stuck with this, and I did not find an answer to how this can be done. I have a parent User object with a set of Operations child objects. These two objects are intended only for the user interface, therefore they represent kinfik representations. Here is the pseudo code
public class User { public int Id {get; set;} public IEnumerable<Operation> Operations {get; set;} public int TotalSuccessfulAccesses {get; set;} // not mapped to the database public int TotalFailedAccesses {get; set;} // not mapped to the database } public class Operation { public int Id {get; set; } public int UserId {get; set; } // FK public int NbSuccessfulAccesses {get; set; } public int NbFailedAccesses {get; set; } }
What would I like to do to get a user with TotalSuccesfulAccesses and TotalFailedAccesses initialized from the child collection, in one round trip to the database.
For each user, we must calculate Sum (Operation.NbSuccessfulAccesses) and Sum (Operation.NbFailedAccesse) and make a prediction, respectively, User.TotalSuccesfulAccesses and User.TotalFailedAccesses .
I tried to play with multi criteria and a few queries, but I am not happy with that. I would like to know, maybe there is an easy way to do this with a projection or something else. Or maybe I missed something.
What would you recommend?
Thanks in advance for your help.
source share