Answer the question
In order to leave comments, you need to log in
EF CodeFirst: what causes an error when creating links?
There are models
public class PriceList
{
public PriceList()
{
PriceListId = Guid.NewGuid();
}
[Key]
public Guid PriceListId { get; set; }
public Guid PriceListCategoryId { get; set; }
public string Name { get; set; }
public int PriceMin { get; set; }
public int PriceMax { get; set; }
public virtual PriceListCategory PriceListCategory { get; set; }
public virtual ICollection<ExecutiveUnitPriceList> ExecutiveUnitPriceLists{ get; set; }
}
public class ExecutiveUnit
{
private ExecutiveUnit()
{
ExecutiveUnitId = Guid.NewGuid();
}
[Key]
public Guid ExecutiveUnitId { get; set; }
public Guid CompanyId { get; set; }
public string Name { get; set; }
public string Specialization { get; set; }
public string Photo { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<ExecutiveUnitPriceList> ExecutiveUnitPriceLists{ get; set; }
}
public class ExecutiveUnitPriceList
{
private ExecutiveUnitPriceList()
{
ExecutiveUnitPriceListId = Guid.NewGuid();
}
[Key]
public Guid ExecutiveUnitPriceListId { get; set; }
public Guid ExecutiveUnitId { get; set; }
public Guid PriceListId { get; set; }
public int RunTime { get; set; }
public virtual ExecutiveUnit ExecutiveUnit { get; set; }
public virtual PriceList PriceList{ get; set; }
}
Answer the question
In order to leave comments, you need to log in
Most likely, you need to specify that the deletion of PriceList did not cascade the ExecutiveUnit. In this case, the child ExecutiveUnitPriceList are deleted cascaded.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<ExecutiveUnitPriceList>()
.HasRequired(a => a.ExecutiveUnit)
.WillCascadeOnDelete(false);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question