Is DbSet<>.Local something to use with special care?

后端 未结 3 1090
忘掉有多难
忘掉有多难 2021-02-05 14:35

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

3条回答
  •  佛祖请我去吃肉
    2021-02-05 15:06

    For those who come after, I ran into some similar issues and decided to give the .Concat method a try. I have not done extensive performance testing so someone with more knowledge than I should feel free to chime in.

    Essentially, in order to properly break up functionality into smaller chunks, I ended up with a situation in which I had a method that didn't know about consecutive or previous calls to that same method in the current UoW. So I did this:

    var context = new MyDbContextClass();
    var emp = context.Employees.Concat(context.Employees.Local).FirstOrDefault(e => e.Name.Contains("some name"));
    

提交回复
热议问题