Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are allowed to have any method you want in your repository :) In both of the cases you mention, it makes sense to return the user with phone list populated. Normally user object would not be fully populated with all the sub information (say all addresses, phone numbers) and we may have different methods for getting the user object populated with different kind of information. This is referred to as lazy loading.</p> <pre><code>User GetUserDetailsWithPhones() { // Populate User along with Phones } </code></pre> <p>For updating, in this case, the user is being updated, not the phone number itself. Storage model may store the phones in different table and that way you may think that just the phones are being updated but that is not the case if you think from DDD perspective. As far as readability is concerned, while the line</p> <pre><code>UserRepository.Update(user) </code></pre> <p>alone doesn't convey what is being updated, the code above it would make it clear what is being updated. Also it would most likely be part of a front end method call that may signifiy what is being updated.</p> <p>For the lookup tables, and actually even otherwise, it is useful to have GenericRepository and use that. The custom repository can inherit from the GenericRepository.</p> <pre><code>public class UserRepository : GenericRepository&lt;User&gt; { IEnumerable&lt;User&gt; GetUserByCustomCriteria() { } User GetUserDetailsWithPhones() { // Populate User along with Phones } User GetUserDetailsWithAllSubInfo() { // Populate User along with all sub information e.g. phones, addresses etc. } } </code></pre> <p>Search for Generic Repository Entity Framework and you would fine many nice implementation. Use one of those or write your own.</p>
 

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