1

We are looking to implement a versioning scheme for our EF Code first data models. Take the following two models as an example:

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

Here, the idea is that a question has multiple alternatives. We want to link an alternative to a question's Id, but not its Version. Likewise, a question can get a reference to all alternatives which has a QuestionId equal to its Id.

How would this be modeled best? Feel free to change the models.

2
  • 1
    Don't model after EntityFramework. Just model your database without thinking about EntityFramework at all. Commented Apr 10, 2013 at 12:41
  • OK. But still it needs to be modeled :) Commented Apr 10, 2013 at 12:42

1 Answer 1

2

I looked at this for several minutes and maybe totally missed the boat, but this might be an option:

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

Theory here is that question and alternatives are all grouped together in one object. The question text is stored on the version, and you should be able to access the current version from the selected alternatives. You could change the Question object to either provide access to all QuestionText objects or just the alternatives.

Then again I could have totally missed the point of your Alternative.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.