Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's not bad at all. Very similar to our setup.</p> <p>Couple of pointers:</p> <p>1 - Use generics for your Repositories. Your code for Attach is very simple, and should not need to be duplicated amongst entities. If you created a <code>GenericRepository&lt;T&gt;</code>, then your attach code would be:</p> <pre><code>public T Attach&lt;T&gt;(T entity) where T : class { Context.GetEntitySet&lt;T&gt;.Attach(entity); // pluralization on (typeof)T.name to get entity set Context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); return entity; } </code></pre> <p>2 - I would seperate the <code>UpdatePhones</code> method into seperate methods. I wouldn't rely on a flag (IsDeleted, etc) to determine the course of action. I would be more explicit.</p> <p>3 - Looks like you have a <code>PhoneRepository</code>? Why? <code>Person</code> is your aggregate root, and <code>Phone</code> is always related to a particular <code>Person</code>, therefore you should only have a <code>PersonRepository</code> in this aggregate boundary. You should be attaching to the <code>Phones</code> ObjectSet` of a particular person.</p> <p>BTW - i assume you have <em>lazy loading</em> disabled? If not, those LINQ operations over the ICollection will cause silent round trips.</p> <p>Apart from the above points (which are mainly design related), optimization-wise your code looks good to me.</p> <p>And a final note - there is another recommended technique (Alex James) for updating entities in a detached context (aka MVC) called the "stub techinque".</p> <p>I asked a question (and solved it myself) a few days ago if your interested, <a href="https://stackoverflow.com/questions/4221275/entity-framework-4-where-to-put-applycurrentvalues-logic">check it out</a>.</p> <p>HTH.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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