复合键和外键

发布于 2024-10-25 13:21:32 字数 1114 浏览 0 评论 0原文

我正在开发 asp.net MVC3 应用程序,我有以下实体

该实体具有复合键(CreditRegistryId 和 Accoubnt No 是主键)。 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;}
}

I am developing asp.net MVC3 application and I have following entity

This entity has composite key (CreditRegistryId and Accoubnt No are primary keys). CreditRegistryId is a foreign key as well. How can I make composite key and foreign key. I am using DbContext API from EF 4.1. I am not using edmx ( ORM designer)

[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; }
}

and other entity lets say is

public class CreditRegistry
        {
public int CreditRegistryId  {get;set;}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

EF 不支持仅使用参与复合键的属性之一的关联。
不确定这个场景是否可以实现。

EF does not support associations that use only one property of the ones that participate in a composite key.
Not sure if this scenario can be implemented.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文