0
我開發asp.net MVC3應用程序,我有以下實體複合鍵和外鍵
這個實體具有複合鍵(CreditRegistryId和Accoubnt號是主鍵)。 CreditRegistryId也是一個外鍵。我如何製作複合鍵和外鍵。我使用EF 4.1中的DbContext API。我不使用EDMX(ORM設計師)
[Table("tbaAccount")]
public class Account
{
[Column(Name="Creditor Registry ID")] // PK FK
public int CreditRegistryId {get;set;}
[Column(Name = "[Account No]")] //PK
public int AccountNo { get; set; }
[Column(Name = "[Date Opened]")]
public DateTime DateOpened { get; set; }
[ForeignKey("tblAccountStatus")]
[Required]
[Column(Name = "Account Status ID")] // FK
public int AccountStatusId { get; set; }
[Required]
[Column(Name = "Date First Reported")]
public DateTime DateFirstReported { get; set; }
[Required]
[Column(Name = "Credit Limit")]
public double CreditLimit { get; set; }
[Required]
public double Balance { get; set; }
}
和其他實體可以說是
public class CreditRegistry
{
public int CreditRegistryId {get;set;}
}