Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

Typical scinario. I have a Database with several tables.
Using VS ORM tool to generate DataContext classes.

Using the Repository pattern, I will create a repository class per table.

BUT the issue is, I want to use interfaces also for ease of testing without having a dabatase.

My question is:
"Do I have to creare an interface per table also, or can I somehow get away with using 1 interface for all tables? noting that each method will take seperate object. i.e a product update methind will take a product object, but customer update method will take customer objects."

Thanks in advance.

Company Table Interface example
internal interface ICompanies
    {
        void Create(Company company);
        void Delete(Company company);
        void Update(Company company);
        void Save();
        IQueryable<Company> Select();
        Company GetSingle(int companyId);
    }


Company Locations Interface example
interface ICompanyLocations
    {
        void Create(CompanyLocation CompanyLocation);
        void Delete(CompanyLocation CompanyLocation);
        void Update(CompanyLocation CompanyLocation);
        IQueryable<CompanyLocation> Select();
        void Save();
        CompanyLocation GetSingle(CompanyLocationID);
    }
Posted
Updated 26-Jul-10 0:05am
v2

Hi,
You can use the IRepository generic interface for all the entities:
public interface IRepository<T>
                where T : class
{
  T GetById(int id);
  IEnumerable<T> GetAll();
  IEnumerable<T> Query(Expression<Func<T, bool>> filter);
  void Add(T entity);
  void Remove(T entity);
}
 
Share this answer
 
v3
Looks like you have a design issue here. CompanyLocation is an entity which is related to the company, right? So getting CompanyLocation individually doesn't make sense. Company should contain CompanyLocation and getting a company will get locations automatically.

So model your interfaces in a logical way rather than one interface per table. I'd suggest you to take a look at nHibernate rather than the VS ORM tool.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900