【发布时间】:2012-12-17 06:24:35
【问题描述】:
存在架构问题。我正在尝试将逻辑层拆分为物理层并且遇到了一些麻烦。这是我想要的设置方式:
- 实体 - 一个 DLL。我的 POCO 课程。没有依赖项。
- DAL - 一个 DLL。包含模型和 DbContext。依赖实体。
- BLL - 一个 DLL。包含 CRUD 函数。依赖 DAL 和实体
- UI - 一个网站项目。与 BLL 对话。
我的问题是在 BLL 中,我做了类似的事情:
''' <summary>
''' The repository
''' </summary>
''' <remarks></remarks>
Private context As MyContext
''' <summary>
''' Instantiate the business layer
''' </summary>
''' <remarks></remarks>
Public Sub New()
context = New MyContext()
End Sub
''' <summary>
''' Insert a general retrieve into the database
''' </summary>
''' <param name="myEntity">The entity to insert</param>
''' <returns>The id of the entity added</returns>
''' <remarks></remarks>
Public Function Create(ByVal myEntity As myEntity) As String
Try
context.myEntity.Add(myEntity )
context.SaveChanges()
Catch ex As Exception
Throw ex
End Try
Return myEntity.id
End Function
但为了在我的实体上调用 Add,我需要对 EntityFramework.dll 的引用,因为我的上下文继承自 DbContext。如果不创建存储库,我不知道如何避免这种情况,这似乎是不必要的额外抽象层,而且我认为我不需要 ti 与 DbContext。
我在这里错过了什么?
【问题讨论】:
标签: asp.net entity-framework webforms n-tier-architecture