我有以下两个2个车型在MVC项目:复合外键,其组合主要的部分关键
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace RiskDotNet.Models
{
public class Customer
{
[Key, Column(Order = 0)]
public string SrcSys { get; set; }
[Key, Column(Order = 1)]
public string CustId { get; set; }
public string CustNm { get; set; }
public virtual ICollection<Account> Accounts { get; set; }
}
}
和
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace RiskDotNet.Models
{
public class Account
{
[Key, Column(Order = 0)]
[ForeignKey("Customer"), Column(Order = 0)]
public string SrcSys { get; set; }
[Key, Column(Order = 1)]
[ForeignKey("Customer"), Column(Order = 1)]
public string CustId { get; set; }
[Key, Column(Order = 2)]
public string AccId { get; set; }
public string BrId { get; set; }
public string ProdId { get; set; }
public virtual ICollection<Balance> Balances { get; set; }
public virtual Customer Customers { get; set; }
}
}
的Customer
可以通过组合键源识别系统(SrcSys
)&客户ID(CustId
)。虽然Account
可以由源系统(SrcSys
),客户ID(CustId
)加上帐户Id(AccId
)标识。但第二种模式不允许我使用另一个列。
请查看您的专家是否有帮助。
Thanx提前。
什么是错误消息? – CodeNotFound
在外键行处重复“列”属性,列中有下划线, – InAction