类定义
Public Class AddressEntity
Private _addressId As Guid
Private m_strStreet As String
Private m_strSuite As String
Private m_strCity As String
Private m_State As String
Private m_strZipCode As String
Private m_strCountry As String
Public Overridable Property Street() As String
Get
Return m_strStreet
End Get
Set(ByVal Value As String)
m_strStreet = Left(Value, 50)
DataChanged(EntityState.Modified, "Street")
End Set
End Property
Public Overridable Property Suite() As String
Get
Return m_strSuite
End Get
Set(ByVal Value As String)
m_strSuite = Left(Value, 50)
DataChanged(EntityState.Modified, "Suite")
End Set
End Property
Public Overridable Property City() As String
Get
Return m_strCity
End Get
Set(ByVal Value As String)
m_strCity = Left(Value, 50)
DataChanged(EntityState.Modified, "City")
End Set
End Property
Public Overridable Property State() As String
Get
Return m_State
End Get
Set(ByVal Value As String)
m_State = Left(Value, 50)
DataChanged(EntityState.Modified, "State")
End Set
End Property
<MaxStringLength(10)>
Public Overridable Property ZipCode() As String
Get
Return m_strZipCode
End Get
Set(ByVal Value As String)
m_strZipCode = Left(Value, 10)
DataChanged(EntityState.Modified, "ZipCode")
End Set
End Property
Public Overridable Property Country() As String
Get
Return m_strCountry
End Get
Set(ByVal Value As String)
m_strCountry = Left(Value, 50)
DataChanged(EntityState.Modified, "Country")
End Set
End Property
<Key>
Public Overridable Property AddressId() As Guid
Get
Return _addressId
End Get
Set(ByVal value As Guid)
_addressId = value
End Set
End Property
Public Class AMAStatementEntity
Private _DateOfService As Nullable(Of DateTime)
Private _FacilityLocation As AddressEntity
Private _BillingAddress As AddressEntity
<Key>
Public Property AMAId() As Guid
Get
Return _amaId
End Get
Set(ByVal value As Guid)
_amaId = value
End Set
End Property
Public Property DateOfService() As Nullable(Of Date)
Get
Return _DateOfService
End Get
Set(ByVal value As Nullable(Of Date))
_DateOfService = value
End Set
End Property
'This was used in Castle Activerecord
'<Nested(ColumnPrefix:="FL")> _
Public Property FacilityLocation() As AddressEntity
Get
Return _FacilityLocation
End Get
Set(ByVal value As AddressEntity)
_FacilityLocation = value
End Set
End Property
'This was used in Castle Activerecord
'<Nested(ColumnPrefix:="BA")> _
Public Property BillingAddress() As AddressEntity
Get
Return _BillingAddress
End Get
Set(ByVal value As AddressEntity)
_BillingAddress = value
End Set
End Property
'Other irrelevant properties cut for brevity.
End Class
数据库表
CREATE TABLE [dbo].[AMA](
[AMAId] [uniqueidentifier] NOT NULL,
[DateOfService] [datetime] NULL,
[FLStreet] [nvarchar](255) NULL,
[FLSuite] [nvarchar](255) NULL,
[FLCity] [nvarchar](255) NULL,
[FLZipCode] [nvarchar](255) NULL,
[FLCountry] [nvarchar](255) NULL,
[FLState] [nvarchar](255) NULL,
[BAStreet] [nvarchar](255) NULL,
[BASuite] [nvarchar](255) NULL,
[BACity] [nvarchar](255) NULL,
[BAZipCode] [nvarchar](255) NULL,
[BACountry] [nvarchar](255) NULL,
[BAState] [nvarchar](255) NULL,
CONSTRAINT [PK_AMA] PRIMARY KEY CLUSTERED
(
[AMAId] ASC
)
) ON [PRIMARY]
鉴于上述类和表结构,我可以,如果可以,我如何正确告诉 Entity Framework 这些类是如何存储在数据库中的?我正在从Castle ActiveRecord(位于NHibernate 之上)迁移,它使用了一个带有选项列前缀的嵌套属性。另外,我不知道这个构造的正确名称(如果有的话)是什么,我知道 TPT、TPC 和 TPH,但我还没有找到它的名称。