Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have this as my repository class and yeah I extend in the table / area repository but still I sometimes have to break DRY.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MvcRepository { public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class { protected System.Data.Linq.DataContext _dataContextFactory; public IQueryable&lt;T&gt; All() { return GetTable.AsQueryable(); } public IQueryable&lt;T&gt; FindAll(Func&lt;T, bool&gt; exp) { return GetTable.Where&lt;T&gt;(exp).AsQueryable(); } public T Single(Func&lt;T, bool&gt; exp) { return GetTable.Single(exp); } public virtual void MarkForDeletion(T entity) { _dataContextFactory.GetTable&lt;T&gt;().DeleteOnSubmit(entity); } public virtual T CreateInstance() { T entity = Activator.CreateInstance&lt;T&gt;(); GetTable.InsertOnSubmit(entity); return entity; } public void SaveAll() { _dataContextFactory.SubmitChanges(); } public Repository(System.Data.Linq.DataContext dataContextFactory) { _dataContextFactory = dataContextFactory; } public System.Data.Linq.Table&lt;T&gt; GetTable { get { return _dataContextFactory.GetTable&lt;T&gt;(); } } } } </code></pre> <p><strong>EDIT</strong></p> <pre><code>public class AdminRepository&lt;T&gt; : Repository&lt;T&gt; where T: class { static AdminDataContext dc = new AdminDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["MY_ConnectionString"].ConnectionString); public AdminRepository() : base( dc ) { } </code></pre> <p>I also have a datacontext which was created using Linq2SQL.dbml class.</p> <p>So now I have a standard repository implementing standard calls like All and Find and in my AdminRepository I have specific calls.</p> <p>Doesn't answer the question of DRY though I don't think.</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