I am trying to create a shared LINQ-TO-SQL repository based on this post , which basically allows you to define a common base class repository, then you can define all your actual repository classes based on a common base.
I want the option of using the repository with or without transfer in the data context, so I decided to create two constructors in the base base class:
public abstract class GenericRepository<T, C>
where T : class
where C : System.Data.Linq.DataContext, new()
{
public C _db;
public GenericRepository()
{
_db = new C();
}
public GenericRepository(C db)
{
_db = db;
}
public IQueryable<T> FindAll()
... and other repository functions
}
To use it, I would intimidate my actual repository class:
public class TeamRepository : GenericRepository<Team, AppDataContext> { }
Now, if I try to use this with a parameter:
AppDataContext db = new AppDataContext();
TeamRepository repos=new TeamRepository(db);
I get an error: "App.Models.TeamRepository" does not contain a constructor that takes 1 argument
, , #, , , : TeamRepository() TeamRepository (db)