开发者

What model structure should I use for tracking changes?

I have a data model that requires tracking changes. I could have as many ~100,000 changes/updates to my model per month. My model involves tracking HOW a task is completed and can be broken down into 3 basic types.

I currently have my model like this but have divided the types of sandwiches into 3 separate controllers because each sandwich is made very differently:

public class Sandwich
{
    public int Id { get; set;开发者_运维技巧 }
    public int SandwichTypeId { get; set; } //This is an enum type
    //About a dozen other properties that define HOW the sandwich gets made
}

I could break it apart like this and match it more to my controllers:

public class PeanutButterAndJellySandwich
{
    public int Id { get; set; }
    //No enum sandwich type
    //About a dozen other properties that define HOW the sandwich gets made
}

public class HamSandwich
{
    public int Id { get; set; }
    //No enum sandwich type
    //About a dozen other properties that define HOW the sandwich gets made
}

//etc

2 Part Question:

  1. Is there any advantage(s) to breaking up the model?
  2. If so, would those advantages be defeated because I would have to add separate tracking tables as well?

Thanks.


In EF I have done something like subclassing the Sandwich class, and using those in the specific controllers.

On the other hand, I've handled things like this by, for example, creating just one more field:

public class Sandwich
{
    public int? CurrentVersion { get; set; } 
    public int Id { get; set; }
    public int SandwichTypeId { get; set; } //This is an enum type
    //About a dozen other properties that define HOW the sandwich gets made
}

This way, a single sandwich can have a lot of previous versions, all of which would point to the current one. In my update routine, I created a duplicate (with the old version's CurrentVersion pointing to the original, now updated, version Id).

This of course requires you to change other places where you list Sandwiches to look only for those which are not revisions.

If you need to reference immediately previous or next versions then you could create int? PreviousVersion and/or int? NextVersion to avoid searches in your database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜