views:

30

answers:

1

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?

A: 

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.

Robert Koritnik
Yes, most of the time I will be showing the last info. I don't understand very well your class, how do you fetch previous edits? you are only saving the last content and the last person to edit it, but how can you see what was there before?
Francisco Noriega
I edited my answer to match your needs. The way I've done it before could be done with an existing DB (even if using the *code first* approach) but with an empty one, this is cleaner. Your model is turned upside down. Mine is more like a normalised DB model.
Robert Koritnik