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# 实体框架实体的版本控制_C#_Entity Framework_Ef Code First_Entity Framework 5 - Fatal编程技术网

C# 实体框架实体的版本控制

C# 实体框架实体的版本控制,c#,entity-framework,ef-code-first,entity-framework-5,C#,Entity Framework,Ef Code First,Entity Framework 5,我们希望为我们的EF代码优先数据模型实现一个版本控制方案。以以下两个模型为例: public class Question { public int Id { get; set; } public int Version { get; set; } public string Text { get; set; } public ICollection<Alternative> Alternatives { get; set; } } public

我们希望为我们的EF代码优先数据模型实现一个版本控制方案。以以下两个模型为例:

public class Question
{
    public int Id { get; set; }
    public int Version { get; set; }
    public string Text { get; set; }

    public ICollection<Alternative> Alternatives { get; set; }
}

public class Alternative
{
    public int Id { get; set; }
    public int Version { get; set; }
    public string Text { get; set; }
    public bool IsCorrect { get; set; }

    public int QuestionId { get; set; }
    public virtual Question Question { get; set; }
}
公开课问题
{
公共int Id{get;set;}
公共int版本{get;set;}
公共字符串文本{get;set;}
公共ICollection替换项{get;set;}
}
公共类替代方案
{
公共int Id{get;set;}
公共int版本{get;set;}
公共字符串文本{get;set;}
公共bool IsCorrect{get;set;}
public int QuestionId{get;set;}
公共虚拟问题{get;set;}
}
在这里,一个问题有多种选择。我们希望将一个备选方案链接到问题的
Id
,而不是其
版本
。同样,一个问题可以获得对所有备选方案的引用,这些备选方案的
QuestionId
与其
Id
相等


如何对其进行最佳建模?请随意更换型号。

我看了几分钟,可能完全错过了机会,但这可能是一个选择:

public class Question
{
    public int QuestionId { get; set; }
    public QuestionText Primary { get; set; }
    public ICollection<QuestionText> Alternatives { get; set; }
}

public class QuestionText
{
    public int QuestionTextId { get; set; }
    public ICollection<QuestionTextVersion> Versions { get; set; }
    public QuestionTextVersion CurrentVersion { get; set; }
}

public class QuestionTextVersion
{
    public int QuestionTextVersionId { get; set; }
    public int Version { get; set; }
    public string Text { get; set; }
}
公开课问题
{
public int QuestionId{get;set;}
公共问题文本主{get;set;}
公共ICollection替换项{get;set;}
}
公共课堂提问文本
{
public int QuestionTextId{get;set;}
公共ICollection版本{get;set;}
公共问题文本版本当前版本{get;set;}
}
公共类问题文本版本
{
public int QuestionTextVersionId{get;set;}
公共int版本{get;set;}
公共字符串文本{get;set;}
}
这里的理论是,问题和备选方案都集中在一个对象中。问题文本存储在版本上,您应该能够从所选备选方案访问当前版本。您可以更改
Question
对象,以提供对所有
QuestionText
对象的访问权限,或者仅提供备选方案


那么,我可能完全没有理解您的
备选方案

不要在EntityFramework之后建模的要点。只需对数据库建模,而不必考虑EntityFramework。好的。但它仍然需要建模:)