Problems creating a Foreign-Key relationship on Entity Framework

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)