在 Entity Framework 代码上首先从数据库交换外键

Exchanged Foreign Key on Entity Framework Code First From data base

我正在使用数据库中的代码优先创建一个 Windows 服务,但我的代码抛出以下异常。我在哪里可以更改此 class 的外键配置,因为看起来列是交叉引用的,列 usu_grpcom 必须引用 codagp 并且 usu_codemp 必须引用 codemp.

e013agp_usu_titefol_Source_e013agp_usu_titefol_Target: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'usu_grpcom' on entity 'usu_titefol' does not match the type of property 'codemp' on entity 'e013agp' in the referential constraint 'e013agp_usu_titefol'.

e013agp_usu_titefol_Source_e013agp_usu_titefol_Target: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'usu_codemp' on entity 'usu_titefol' does not match the type of property 'codagp' on entity 'e013agp' in the referential constraint 'e013agp_usu_titefol'.

您最好分享 类 实现以便更好地理解。我根据我的理解为您提供代码。您可以使用类似的代码来解决您的问题。

public class usu_titefol
{
    public e013agp e013agp { get; set; }
    [ForeignKey("codemp")]
    [Required]
    public int usu_grpcom { get; set; }
}