Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What we did at work was to implement a pattern like this:</p> <pre><code>interface ICRUD&lt;T&gt; : ICreatable&lt;T&gt;, IRetrievable&lt;T&gt;, IUpdatable&lt;T&gt;, IDeletable&lt;T&gt; { } interface ICreatable&lt;T&gt; { T Create(); } interface IRetrieve&lt;T&gt; { T Retrieve(params object[] keys); } interface IUpdatable&lt;T&gt; { void Update(T existing); } interface ICreatable&lt;T&gt; { void Delete(T existing); } </code></pre> <p>And then we created an Entity-powered base repository:</p> <pre><code>public abstract class BaseRepository&lt;TModel, TEntities&gt; where TEntities : IDbSet&lt;TModel&gt; { protected TEntities Entities {get; set;} protected DbContext Db {get; set;} public BaseRepository (DbContext db, TEntities entities) { Db = db; Entities = entities; } public virtual TModel Create() { return Entities.Create (); } public virtual TModel Retrieve (params object[] keys) { return Entities.Find (keys); } public virtual void Update (TModel existing) { Db.Entry(existing).State = Modified; } public virtual void Delete (TModel existing) { Db.Entry(existing).State = Removed; } } </code></pre> <p>If you notice, the BaseRepository doesn't actually use ICRUD, just has identical method signatures. Since we code to interfaces, this lets us use a lot of shared code without exposing functionality we don't want with the base classes. A developer is free to implement the data store however they wish (ICRUD can talk to a webservice, for instance) with no knowledge of Entity, or they're also free to augment behavior provided by the BaseRepository by overriding any of the provided methods and doing something differently.</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. 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.
 

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