相关疑难解决方法(0)

.net中的存储库模式和继承

我对存储库设计模式很陌生,在尝试实现它时,我已经达到了死胡同,关于继承.

即使我开始朝着正确的方向前进,我也不确定.

所以基本上我将有一个抽象的基类Product,例如id和imagePath,并且将有几个继承自此的产品.

namespace Common
{
    public abstract class Product
    {
        public int Id { get; set; }
        public string ImgPath { get; set; }
    }

    public class Scale : Product
    {
        public int AdditionalProperty { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在存储库如下:

public class BaseRepository
{
    protected TEstEntities1 _dataContext = new TEstEntities1();

    public BaseRepository()
    {
        _dataContext = new TEstEntities1();
    }
}

public interface IProductRepository 
{
    Common.Product Get(int id);
    void Add(Common.Product p);
    void Update(Common.Product p);
    List<Common.Product> ListAll();
}

public class ProductRepository …
Run Code Online (Sandbox Code Playgroud)

.net c# inheritance entity-framework repository-pattern

6
推荐指数
1
解决办法
5125
查看次数