c# - Entity Framework 存储库模式继承

标签 c# linq design-patterns ef-code-first repository-pattern

class A 
{
public int id {get; set;}
}

class B : A
{
}

class C : A
{    
}

现在为 B 和 C 设置一个单独的存储库是否有意义,或者我应该将类型信息传递给 A 的存储库中的方法并从那里返回内容。

class ARepository : RepositoryBase<Context>,IARepository
{
A GetById (int id )
{
//some linq query here
}

//should this be here or in a separate repository
A GetBByID (int id)
{
}

}

我会去另一个存储库的原因是如果我想要

class D : A
or Class E : C

这可能会开始变得困惑和棘手。

那么最好的方法是什么?

最佳答案

我更喜欢每个 EntityFramework 上下文有一个大型存储库,它简化了维护。

关于c# - Entity Framework 存储库模式继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11707364/

相关文章:

c# - 在 LINQ Select 期间访问递增整数

c# - 如何选择对包含多行 LIST 的条目使用 LINQ?

c# - 这个 LINQ 表达式可以从方法语法转换为查询语法吗?

java - 如何避免观察者模式中的无限循环?

java - 设计问题: Dynamically changing GUI -> sending implementation classes as soap attachments

ruby-on-rails - MVC Web 框架中不相关 View 的优雅解决方案是什么?

c# - ASP.NET/ GridView : HeaderStyle-CssClass has no effect

c# - 全屏WPF应用程序充当操作系统

c# - 输出 html 的 WPF 应用程序

c# - 如何使用 LINQ 查找特定属性的副本?