The user in our application has the possibility to add, delete and modify an object graph.
I am using Cocktail's UnitOfWork to collect the changed Entitys and start a "BusinessProcess" to check for certain entrys in the Object Graph.
Lets say, i want to Check, if the user has added an Entry in the Person.Department, where Department is an RelatedEntityList of Person.
The user has added the Department on the Person.Department and i am using Linq to check weather there is a special Department of "Administrator".
My Linq Query looks like this.
var adminDepartement = person.Departement.Where(x=>x.Name.Equals("Administrator")).FirstOrDefault();
This query works great, if the departement was already there. But when the user has just added the departement with this session, i get a null back from the RelatedEntityList.
Is there any trick to search via Linq for new added entrys?
Or do i have to work with the EntityManager directly?
On the second Save, the Linq Query returns the adminDepartement correctly, but i need this validation before the user saves.
I found my issue. I was Querying on the EntityId Person.Department.Id wich is 0 when the entity is created, and be set at database level, when the commit has finished.
I am now using Person.DepartementId to query for existing entrys.