关系约束中的从属角色和主要角色中的属性数必须相同。 [英] The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical.
问题描述
我有两个实体
1.Status
2.ActionProgress
在状态实体中,我想要成为复合键/
I have two entities
1.Status
2.ActionProgress
In status entity,i want to become composite keys/
public class Status
{
[Key, Column(Order = 0)]
public int Id { get; set; }
public string Name { get; set; }
[Key, Column(Order = 1)]
public int LanguageId { get; set; }
[ForeignKey("LanguageId")]
public virtual Language Language { get; set; }
}
和其他实体是
and other entity is
public class ActionProgress
{
[Key,Column(Order=0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ActionProgressID { get; set; }
public int? StatusID { get; set; }
[ForeignKey("StatusID")]
public virtual Status ActionProgressStatus { get; set; }
}
i我正在使用代码第一种方法。当我运行我的应用程序时,
抛出错误,
关系约束中的从属角色和主要角色中的属性数量必须相同。
i不知道我做错了什么。请帮助
i am using code first approach.when i run my application,
the error is throwing,
"The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical."
i don't know what i am doing wrong.please help
推荐答案
我用我的所有实体配置流利的API
(我可以写
I do all my entity configuration with the fluent API
(where I could write
...HasForeignKey(e => new { e.ID, e.LanguageID })
我认为与dataanotations相当的是:
I think the equivalent with dataanotations would be:
public class ActionProgress
{
[Key,Column(Order=0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ActionProgressID { get; set; }
[ForeignKey("ActionProgressStatus", Column(Order = 0)]
public int? StatusID { get; set; }
[ForeignKey("ActionProgressStatus", Column(Order = 1))]
public int? StatusLanguageID { get; set; }
public virtual Status ActionProgressStatus { get; set; }
}
请自己试试......会的好的,如果你留下一个便条,如果它有用......
Please try for yourself... Would be nice if you leave a note if it worked...
这篇关于关系约束中的从属角色和主要角色中的属性数必须相同。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!