【问题标题】:Versioning Entity Framework entities版本控制实体框架实体
【发布时间】:2013-04-10 12:38:12
【问题描述】:

我们正在寻求为我们的 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; }
}

这里的想法是一个问题有多种选择。我们想要链接到问题的Id,而不是Version。同样,一个问题可以引用所有具有QuestionId 等于其Id 的备选方案。

如何最好地建模?随意更改模型。

【问题讨论】:

  • 不要模仿 EntityFramework。只需为您的数据库建模,根本无需考虑 EntityFramework。
  • 好的。但它仍然需要建模:)

标签: c# entity-framework ef-code-first entity-framework-5


【解决方案1】:

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

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; }
}

这里的理论是问题和备选方案都组合在一个对象中。问题文本存储在版本中,您应该能够从选定的备选方案中访问当前版本。您可以更改 Question 对象以提供对所有 QuestionText 对象的访问权限或仅提供替代方法。

那么我可能完全错过了你的Alternative

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2013-06-16
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多