Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for clarifying your point. I am adding this as another answer since there is quite a bit to say on the matter.</p> <p>AFAIK, there is no strict universal definition of UoW, so the topic is up for debate of course. My points are the following:</p> <ol> <li><p>You are adding an entity to the context, but trying to fetch it from the db. Concluding that ObjectContext is not a correct implementation of UoW is not logical.</p></li> <li><p>If you are adding entities to the context in order to later get them out for some reason before persisting changes to the db, you aren't using EF as it is meant to be used. Generally you shouldn't use ObjectStateManager to do that, but you can:</p> <pre><code>Blog addedBlog = context. ObjectStateManager. GetObjectStateEntries(EntityState.Added). Where(ent =&gt; (ent.Entity is Blog) &amp;&amp; ((Blog)ent.Entity).BlogID == blogID). Select(ent =&gt; ent.Entity as Blog). SingleOrDefault(); </code></pre></li> <li><p>A unit of work is a context object that maintains lists of business entities, tracks the changes to their state during one business transaction. Does EF ObjectContext do that? Yes. Does it provide a reasonable syntax to retrieve an object that is in state "Added"? No, but that's not a requirement for a "correct" UoW implementation anyways. Don't forget - EF is an ORM, and the goal is to track changes to your db in code, and not changes between different parts of your code (that's what you have your business logic for).</p></li> </ol> <p>And regarding: "what is the point of UoW if I have to persist every entity on its own and not in batch" - the point is that you can add a bunch of objects to the context, and then persist them all in one go by calling SaveChanges. As I already mentioned, the context isn't meant to be used for "carrying" your business objects around. You can, however, retrieve them from ObjectStateManager without persisting changes to the DB if you want to.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload