c# - Entity Y has 2 FK to entiy X not working with EF 6 -
i had code working using ef5, not complains cyclic dependencies:
public class supplier { public int supplierid { get; set; } [foreignkey("supplierid")] public company suppliere { get; set; } public int companyid { get; set; } [foreignkey("companyid")] [inverseproperty("suppliers")] public virtual company company { get; set; } } public class company { public int companyid { get; set; } [inverseproperty("company")] public icollection<client> clients { get; set; } [inverseproperty("company")] public icollection<supplier> suppliers { get; set; } }
and fluent configuration like:
modelbuilder .entity<supplier>() .hasrequired(c => c.company) .withmany(v => v.suppliers) .willcascadeondelete(false);
also have code configure keys fr supplier entity:
public class supplierconfiguration: entitytypeconfiguration<supplier> { public supplierconfiguration() { haskey(c => new {c.companyid, c.supplierid}); } }
i error message cyclic dependencies:
introducing foreign key constraint 'fk_dbo.supplier_dbo.company_companyid' on table 'supplier' may cause cycles or multiple cascade paths. specify on delete no action or on update no action, or modify other foreign key constraints.
as mentionned used work in ef5, migrated ef6 , started getting this.in addition have similar class called client
, works fine it.
any ideas?
edit:
this same code client:
public class client { public int clientid { get; set; } [foreignkey("clientid")] public company cliente { get; set; } public int companyid { get; set; } [foreignkey("companyid")] [inverseproperty("clients")] public virtual company company { get; set; } }
Comments
Post a Comment