Problems creating a Foreign-Key relationship on Entity Framework

前端 未结 1 1277
误落风尘
误落风尘 2020-12-28 12:28

i\'m having trouble configuring a foreign key relationship in my Entity Framework fluent Api:

Here is the head of the report:

 public class Testata
{         


        
1条回答
  •  被撕碎了的回忆
    2020-12-28 12:53

    There is a conflict between your foreign key property in class Dettaglio...

    public virtual int IDTEST { get; set; }
    

    ...which has a non-nullable type (int) and therefore cannot be optional and your mapping...

    this.HasOptional(t => t.TEST_TABLE) //...
    

    ...where you want the relationship to be optional.

    If you indeed want an optional relationship use a nullable FK property:

    public virtual int? IDTEST { get; set; }
    

    Otherwise you must use HasRequired for a required relationship with a non-nullable FK property.

    0 讨论(0)
提交回复
热议问题