gpt4 book ai didi

.net - EdmAssociationConstraint : : The number of properties in the Dependent and Principal Roles in a relationship constraint

转载 作者:行者123 更新时间:2023-12-03 02:23:34 26 4
gpt4 key购买 nike

我遇到了 EdmAssociationConstraint: : EF 5 中的关系约束中的从属角色和主体角色中的属性数量出现此异常

我想使用数据注释解决此问题

public class Task
{
[Key, Column(Order = 0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int TaskId { get; set;}
public string Name { get; set; }
}

public class Trigger
{
[Key, Column(Order = 0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int TriggerId { get; set; }
public string Name { get; set; }

[Key, Column(Order = 1)]
public int TaskId { get; set; }

[ForeignKey("TaskId")]
public virtual Task Tasks { get; set; }
}

public class TriggerHistory
{
[Key, Column(Order = 0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int TriggerHistoryId { get; set; }

[Key, Column(Order = 1)]
public int TaskId { get; set; }

[ForeignKey("TaskId")]
public virtual Task Task { get; set; }

[Key, Column(Order = 2)]
public int TriggerId { get; set; }

[ForeignKey("TaskId")]
public virtual Trigger Triggers { get; set; }

public string Name { get; set; }
}

最佳答案

您的触发器类具有组合键(TriggerId、TaskId)。但是您的 TriggerHistory 具有仅使用 TaskId 属性定义的 ForeignKey 的 Trigger 导航属性。

尝试更改 Triggers 属性上的 ForeignKey,如下所示:

[ForeignKey("TriggerId,TaskId")]
public virtual Trigger Triggers { get; set; }

也许 Triggers 属性应该命名为“Trigger”,因为这不是 Trigger 对象的集合。

关于.net - EdmAssociationConstraint : : The number of properties in the Dependent and Principal Roles in a relationship constraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17369941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com