亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在存儲庫模式(MVC)中擁有多個類

如何在存儲庫模式(MVC)中擁有多個類

C#
郎朗坤 2021-10-24 20:02:54
我對存儲庫模式有點困惑,在這里我寫了我的代碼然后我解釋: public  interface IRepositoryTest<T> where T:class{  IEnumerable<T> SelectAll(Expression<Func<T, bool>> predicate);}這是上述簽名的實現: public class RepositoryTest<T>:IRepositoryTest<T> where T:class{    private CentralEntities db = null;    private DbSet<T> table = null;    public RepositoryTest() {    this.db = new CentralEntities();    table = db.Set<T>();                        }    public RepositoryTest(CentralEntities db)    {        this.db = db;        table = db.Set<T>();    }    public IEnumerable<T> SelectAll(Expression<Func<T, bool>> predicate)    {        return table.Where(predicate).ToList();    }}現在在我的控制器中,如果我想使用這個存儲庫,我必須做這樣的事情:  IRepositoryTest<UserRoles> _repository = null;    public DashbrdController(IRepositoryTest<UserRoles> _repository)    {        this._repository = _repository;    }    public DashbrdController()    {        this._repository = new RepositoryTest<UserRoles>();    }    public ActionResult DashBrd()    {        var rslt = _repository.SelectAll(s=>s.user_id=="myName");                 return View();    }這里的問題是,在我的控制器中,我只能使用模型中的一個類,如您所見(UserRoles),如果我想向該控制器添加另一個類,我該怎么做?我想有多個類加入他們,但在我的控制器的構造函數中我只能使用一個類,問題出在哪里?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 230 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號