Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF CF将一对一与一对多关系结合起来_C#_Entity Framework_Ef Code First_Entity Relationship_Foreign Key Relationship - Fatal编程技术网

C# EF CF将一对一与一对多关系结合起来

C# EF CF将一对一与一对多关系结合起来,c#,entity-framework,ef-code-first,entity-relationship,foreign-key-relationship,C#,Entity Framework,Ef Code First,Entity Relationship,Foreign Key Relationship,我对此做了研究,但没有找到任何解决办法。我正在使用SQL CE 4.0,我希望建立如下关系: public class Process { [Key] public int Id {get;set;} public string Name {get; set;} public int CurrentStageID {get;set;} [ForeignKey("CurrentStageID")] public virtual Stage CurrentSta

我对此做了研究,但没有找到任何解决办法。我正在使用SQL CE 4.0,我希望建立如下关系:

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;}
}
有人能帮我吗

广告。 如果我加上.willfalse;我得到:

在模型生成过程中检测到一个或多个验证错误:

多重性与关系“Process\u Stages”中角色“Process\u Stages\u Source”中的引用约束冲突。 因为从属角色中的所有属性都不可为null,所以主体角色的多重性必须为“1”

modelBuilder.Entity<Process>()
     .HasMany(p=>p.Stages)
     .WithRequired(s=>s.Process)
     .HasForeignKey(s=>s.ProcessId);