Question

I an developing a page where users will be able to add and modify existing content, its not a wiki per sé but sort of, like SO's editing abilities.

I am working with EF4 and the new Code First approach in the latest CTP, so what would be the best class design for this?

my current guess is something like this:

public class VersionableText
{
   public int Id { get; set; }
   public DateTime Date{ get; set; }
   public String Text{ get; set; }

   public virtual User User{ get; set; }  
}

and then use it in my other entities, in a SO context it could be something like this

public class Question
{
   public int Id {get; set;}
   public virtual VersionableText Title {get; set;}
   public virtual VersionableText Content{get; set;}
   ...
}

But I'm not really convinced by it.. since I am also going to have tags, ability to delete/undelete posts, rollback, etc. Do you know how to properly design classes that help me version the content properly?

Was it helpful?

Solution

Aim for simplicity

The main question that you need to ask yourself is Are you going to show all versions all the time or the latest version most of the time and all of them on request? Similar to here. Most of the time you only see the latest version.

If this is the same with our case I wouldn't care so much about these versions. But when you'd want to show them all on one page class design more or less depends on the way that you'd like to show it. Is it going to be showing changes and things like that.

I'd rather have a class like:

public class Question
{
    public int Id { get; set; }
    public QuestionStatus Status { get; set; }
}

public class QuestionHistory
{
    public Question Question { get; set; }

    public string Title { get; set; }
    public string Content { get; set; }

    public User Author { get; set; }

    public DateTime Created { get; set; }

    public IList<Tag> Tags { get; set; }
}

And when I'd display all of them I'd just return a list of these ordered by LastChange. I've added tags list but I didn't add any of the other process-related properties related to question state. It hugely depends on the process sequence.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top