C# 实体框架实体的版本控制
我们希望为我们的EF代码优先数据模型实现一个版本控制方案。以以下两个模型为例: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
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。好的。但它仍然需要建模:)