How do I handle table relationships with the repository pattern?

后端 未结 2 602
旧时难觅i
旧时难觅i 2021-02-07 14:08

I\'m implementing the repository pattern as part of an ASP.NET MVC site. Most examples I\'ve seen of repositories are fairly simple. For example here\'s a typical abstract repos

2条回答
  •  孤城傲影
    2021-02-07 14:54

    Once you have defined your aggregate roots you should create very specific repository interfaces (such as IProductRepository) for these, and have your service layer consume them.

    Such as...

    public interface IProductRepository
    {
        IList GetProductsInCategory(Category c);
        Product GetProductBy(int id);
        IList GetActiveProductCategories();
    }
    

    Then in your concrete implementation of IProductRepository you would consume the generic repository and query your related entities and join them as required.

提交回复
热议问题