For a few days now, I have been struggling with retrieving my entities from a repository (DbContext
).
I am trying to save all the entities in an atomic act
As mentioned by Terry Coatta, the best approach if you don't want to save the records first would be checking both sources.
For example:
public Person LookupPerson(string emailAddress, DateTime effectiveDate)
{
Expression> criteria =
p =>
p.EmailAddress == emailAddress &&
p.EffectiveDate == effectiveDate;
return LookupPerson(_context.ObjectSet.Local.AsQueryable(), criteria) ?? // Search local
LookupPerson(_context.ObjectSet.AsQueryable(), criteria); // Search database
}
private Person LookupPerson(IQueryable source, Expression> predicate)
{
return source.FirstOrDefault(predicate);
}