我有一个 ASP.NET MVC3 应用程序。
在我的应用程序中,我有以下 EF 类(hasCauses
和isOfProblems
是导航属性):
Problem {string ProblemId, string ProblemName, string ProblemDesc, bool solved, hasCauses}
Cause {string CauseId, string CauseName, string CauseDesc, isOfProblems}
ProblemCause {string ProblemId, string CauseId}
我的存储库方法只返回EF对象(原因相同)
IQueryable<Problem> GetProblemsById(string problemId)
现在,在我的服务图层中,我必须创建一个对象SolvedProblems
,其中包含其他字段,ProblemId和CauseId,当然它们必须相关(根据{ {1}})。从我的服务图层我无法“看到”ProblemCause
表,因为我没有使用导航属性(它们仅在存储库中使用)。因此,我可以创建一个方法:
ProblemCause
在迭代IQueryable<Cause> GetProblemsByCauseId(string causeId)
的同时填充ProblemCause
。但是,如果不是两个表(+关联),我有3个或更多表互连?是否值得制作这个嵌套循环或将所有逻辑带到存储库(我可以在哪里使用导航属性)并将Problems
返回到SolvedProblems
?
答案 0 :(得分:0)
如果这些只是简单的连接,我认为解决这个问题的最简单方法是在数据库中创建一个视图,并在EF中将SolvedProblems
映射到它。