2011-08-02 185 views
1

我有一个数据模型,需要跟踪更改。我可以每月对模型进行多达100,000次的更改/更新。我的模型涉及跟踪一项任务如何完成并可以分解为三种基本类型。应该使用什么模型结构来跟踪更改?

目前,我有我的模型是这样,但有分歧的各类三明治成3个独立的控制器,因为每个三明治是由非常不同:

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 
} 

,我就能把它拆开,这样更符合它我控制器:

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 
} 

//等

2部分问题:

  1. 是否有任何优势来分解模型?
  2. 如果是这样,那么这些优点是否会被击败?因为我将不得不添加单独的跟踪表?

谢谢。

回答

1

在EF中,我做了类似于三明治类的子类化,并使用特定控制器中的类。

在另一方面,我已经处理这样的事情,例如,创建只是多了一个领域:

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 
} 

这样,一个三明治可以有很多以前的版本中,所有的这将指向当前的一个。在我的更新例程中,我创建了一个副本(旧版本的CurrentVersion指向原始的,现在更新的版本ID)。

这当然要求你改变你列出三明治的其他地方,只查看那些不是修订版的地方。

如果您需要立即引用上一个或下一个版本,则可以创建int? PreviousVersion和/或int? NextVersion以避免在数据库中进行搜索。

+0

谢谢Kensai。这是一个有趣的想法,我今天会看看。 – trevorc