Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've not seen Interfaces used to decouple EF. I know they are used for decoupling with dependency injection, but perhaps there is too much going on with EF behind the scenes for this to work (dynamic proxies, change detection).</p> <p>I'd suggest implementing a Repository layer.</p> <p><strong>Step 1</strong></p> <p>Start with the simplest pattern - model (Person and Book) in a domain and EF in a DAL layer, using the standard EF procedure for code first. EF implements repository features in the <code>DbSet&lt;Person&gt;</code> and <code>DbSet&lt;Book&gt;</code> (but of course this type of repository is locked into EF).</p> <p>Make a deliverable app work with this pattern, you can demo functionality quite quickly. This allows you to focus on app logic and not worry too much about persistence.</p> <p><strong>Step 2</strong></p> <p>Put a repository class or classes between domain and DAL. Replace the domain calls to <code>DbSet&lt;Person&gt;</code> and <code>DbSet&lt;Book&gt;</code> with calls to <code>IQueryable&lt;Person&gt;</code> and <code>IQueryable&lt;Book&gt;</code> in the repository. The repository collections initially just point at the EF <code>DbSet&lt;&gt;</code> collections.</p> <p>Implement Save() in the repository as well. Initially, it just calls DbContext.SaveChanges().</p> <p>Check the functionality stays the same.</p> <p><strong>Step 3</strong></p> <p>Replace the source of the repository <code>IQueryable&lt;&gt;</code>'s with whatever is equivalent in your new DAL. This may or may not be tricky, depending on the shape of the new DAL.</p> <p>I followed this kind of process - started with an XML serialized DAL, moved it to EF, refactored one table back to a local XML file, and next step will be to refactor another table to a web service on an ESB.</p> <p><strong>BTW</strong>, you mention replacing EF with SQL for performance. We found EF slow for bulk inserts, because of the row-by-row style it uses.</p> <p>To get around this, I implemented SqlBulkCopy within the EF based repository (instead of wholesale replacement of EF which has other features we really liked). It's quick, but takes a while to piece together.</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. 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