1

我正在使用 Entity Framework 5 CodeFirst 开始一个新的 ASP.NET MVC 项目。要开发的应用程序最初将使用许多不同的查找表,其中一些用于可以分配给产品(在本例中为枪)的简单属性

例如

  • 物品状况(差、一般、好、优秀等)
  • 枪方向(左手,右手,灵巧等)

这些“分类/属性”表大约有 10 多个。

此外,还需要“制造”和“模型”。这两个是相关的(因为一个 Make 可以有许多不同的模型)。

最后,一些分类表需要相互关联。例如,一些'Makes'只生产某些类型的枪('GunTypes'查找表),而一些Gun Mechanisms('GunMechanisms'查找表)只与某些枪类型相关。

最初,我为每个实体设计了一个模型类,实现了处理上述要求的必要关系。但是,由于某些元素需要重新用于此应用程序的非枪支版本,因此我被要求摆脱这些元素/类/表中的每一个,而是使用更通用的方法具有“类别”和“术语”实体。

例如,我最初选择了类似下面的东西......

public class Category
{
    // A Category would be, for example, 'Gun Condition', 'Gun Orientation', 'Make' etc.
    public int Id { get; set;}
    public string Name { get; set;}

    // A Category will have any number of Terms associated with it.
    public virtual ICollection<Term> Terms { get; set; }
}

public class Term
{
    // A Term would be, for example, 'Excellent Condition', 'Good Condition', 'Left-Handed', 'Right-Handed' etc.
    public int Id { get; set;}
    public string Name { get; set;}

    // A Term belongs to a Category.
    public virtual Category Category { get; set; }
}

public class Gun
{
    // Edited for brevity.
    public int Id { get; set;}
    public string Descrip { get; set;}

    // All of the terms (what were originally properties), e.g. 1 Term in the collection would be 'Excellent Condition' with the Category 'Gun Condition'. A 2nd Term might be 'Left-Handed' with the Category 'Gun Orientation', and so on. 
    public virtual ICollection<Term> Terms { get; set;}
}

但是,如上所述,我需要能够处理:

a) 诸如“制造”和“模型”之类的项目,它们相互关联;

b)“多对多”风格的场景,其中“制造”仅产生某些“枪型”,而“枪型”将与某些“枪机”相关(例如,气步枪(枪型)将同时具有“ Break Barrel' & 'Pre-charged' Gun Mechanism)。

我真的在为这个模型设计的实施而苦苦挣扎,这是作为一项坚定的要求提出的。

4

0 回答 0