Entity Framework 和 属性 个容器

Entity Framework and property containers

我正在处理一组 EF 数据 类,其中一个 类 在属性上相当大。但是,可以将许多属性分组到子类别中,我想这样做是为了帮助清楚。它也被开发为 Code First。

例如对于员工,以下是在 EF 中实现的。

Public Class Employee

    Public Overridable Property ID As Integer
    Public Overridable Property Surname as String
    Public Overridable Property FirstName as String
    Public Overridable property Age As Byte
    Public Overridable Property StreetAddress as String
    Public Overridable Property Suburb as String
    Public Overridable Property State as String
    Public Overridable Property PostCode As String

End Class

所有数据都在一个员工中 table。如果我使用纯 类,那么我会为所有员工详细信息提供一个分组对象,以避免员工混乱,如下所示:

Public Class Employee
    Private cgAddress AS EmployeeAddress

    Public Overridable Property ID As Integer
    Public Overridable Property Surname as String
    Public Overridable Property FirstName as String
    Public Overridable property Age As Byte

    Public ReadOnly Property Address As EmployeeAddress
        Get
            If cgAddress Is Nothing Then
                cgAddress = New EmployeeAddress
                ' Any population.
            End If

            Return cgAddress
        End Get
    End Property 

End Class

Public Class EmployeeAddress

    Public Overridable Property StreetAddress as String
    Public Overridable Property Suburb as String
    Public Overridable Property State as String
    Public Overridable Property PostCode As String

End Class

好像到处都找不到类似的问题(可能是搜索知识不够),所以我的问题是:

是否可以在没有单独地址的情况下在 EF 下进行配置 table,如果可以,映射是如何配置的?

进一步阅读复杂类型可以为我解答这个问题。它没有给我 collections 的进一步步骤,但它解决了分组问题。

http://visualstudiomagazine.com/articles/2014/04/01/making-complex-types-useful.aspx http://weblogs.asp.net/manavi/associations-in-ef-4-1-code-first-part-2-complex-types