【问题标题】:get Generic CRUD operation in EF在 EF 中获取通用 CRUD 操作
【发布时间】:2011-02-08 10:39:38
【问题描述】:

我可以使用任何方式或设计模式来获取通用 CRUD 操作吗?

因为我正在使用数据层中的 EF 开发 n-tire 应用程序,并且我不想在每个实体中使用 CRUD 函数。

您的帮助将不胜感激

【问题讨论】:

    标签: wcf architecture repository-pattern


    【解决方案1】:

    您可以使用Repository 模式,将存储库实现为接口,然后实现基类。例如:

    IRepository where T : class
    void Save(T entity )
    T FindById( T id ) ....

    EntityFrameworkRepositoryBase : IRepository
    无效保存(T 实体)
    { // 做 EF 特定的东西 }....

    然后对于给定的实体,您可以创建(或注入)一个具体的存储库:

    PersonRepository : EntityFrameworkRepositoryBase

    从那里,只需调用 PersonRepository 来保存或查找人员。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 2013-07-08
      • 2016-11-03
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 2018-06-14
      相关资源
      最近更新 更多