1
我在表Account和AccountProperties之間的數據庫中具有一對一的關係,如下所示。使用實體框架映射一對一關係到單個實體4.1代碼優先方法
CREATE TABLE Account(
[ID] [int] IDENTITY(1,1) NOT NULL,
[AccountName] [varchar](255),
CONSTRAINT [PK_Account]
PRIMARY KEY CLUSTERED ([ID] ASC)
) ON [PRIMARY]
CREATE TABLE AccountProperties(
[AccountHistoryID] [int] IDENTITY(1,1) NOT NULL,
[AccountID] [int] NOT NULL,
[Password] [varchar](50) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AccountProperties] WITH NOCHECK
ADD CONSTRAINT [FK_AccountProperties_Account]
FOREIGN KEY([AccountID]) REFERENCES [dbo].[Account] ([ID])
我想將這兩個表映射爲使用外鍵AccountID的單個實體,如下所示。
public class Account
{
[Key]
public int ID { get; set; }
public string AccountName { get; set; }
public string Password { get; set; }
}
有人可以給我正確的映射使用流利的API?