c# - EF CF combine one to one with one to many relations -
c# - EF CF combine one to one with one to many relations -
i've done research that, didn't find solution. i'm using sql ce 4.0 , want create relations like:
public class process { [key] public int id {get;set;} public string name {get; set;} public int currentstageid {get;set;} [foreignkey("currentstageid")] public virtual stage currentstage {get;set;} public virtual icollection<stage> stages {get;set;} } public class stage { [key] public int id {get;set;} public string name {get; set;} public int processid {get;set;} [foreignkey("processid")] public virtual process process {get;set;} } but during database initialization exception:
the referential relationship result in cyclical reference not allowed. [ constraint name = fk_dbo.stages_dbo.processes_processid ]
such relation correct?
i utilize onmodelcreating() method:
modelbuilder.entity<process>() .hasmany(p=>p.stages) .withrequired(s=>s.process) .hasforeignkey(s=>s.processid); anyone can help me that?
ad. if add together .willcascadeondelete(false); get:
one or more validation errors detected during model generation:
sqlceengine.proces_etapy: : multiplicity conflicts referential constraint in role 'process_stages_source' in relationship 'process_stages'. because of properties in dependent role non-nullable, multiplicity of principal role must '1'
c# entity-framework ef-code-first entity-relationship foreign-key-relationship
Comments
Post a Comment