I'm trying to create an one to many relation, where a TypeOfImmobile can have one Immobile or more. Here's my model classes :
public class TypeOfImmobile
{
public int Id { get; set; }
[Display(Name = "Type Of Immobile")]
public string Designation { get; set; }
public ICollection<Immobile> Immobiles { get; set; }
}
public class Immobile
{
public int Id { get; set; }
public int TypeOfImmobileId { get; set; }
public virtual TypeOfImmobile TypeOfImmobile { get; set; }
}
Error occurred when I create an Immobile:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Immobiles_dbo.TypeOfImmobiles_TypeOfImmobilesId". The conflict occurred in database "aspnet-ARQSI-IT2-20151031052056", table "dbo.TypeOfImmobiles", column 'Id'. The statement has been terminated.
public virtual ICollection<Immobile> Immobiles { get; set; }maybe you missedvirtual