我试图为库存管理系统设计一个数据库。这是我的代码优先的数据模型设计。但是我觉得在餐桌设计中有一些问题。数据库设计的实体框架中的导航属性
Supplier Table
public class Supplier
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int SupplierId { get; set; }
[Index, MaxLength(50),Display(Name="Company Name"),Required]
public string ComapnyName { get; set; }
[Index, MaxLength(50),Display(Name="Contact Person"),Required]
public string ContactPerson { get; set; }
[Column(TypeName = "ntext"),Required]
public string Address { get; set; }
[Required,Display(Name="Mobile Number")]
public string MobileNumber { get; set; }
[Display(Name="Land Line Number")]
public string LandLineNumber { get; set; }
[DataType(DataType.EmailAddress),Display(Name="Email")]
public string Email { get; set; }
[HiddenInput]
public DateTime? Date_From { get; set; }
[HiddenInput]
public DateTime? Date_To { get; set; }
[Required]
public bool Active { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<Category> Categories { get; set; }
}
Category Table
public class Category
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CategoryId { get; set; }
[Required,Index,MaxLength(50),Display(Name="Category Name")]
public string CategoryName { get; set; }
[Column(TypeName = "ntext"),Display(Name="Category Description")]
public string CategoryDesc { get; set; }
[HiddenInput]
public DateTime? Date_from { get; set; }
[HiddenInput]
public DateTime? Date_to { get; set; }
[Required]
public bool Active { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<Supplier> Suppliers { get; set; }
}
什么是想在这里是如下:在分类表]一个类别可以有多个产品和单一类别可以有多个供应商。 [在供应商表中]一个供应商可以提供多种产品,也可以供应多种类别。
但是我的桌子设计不利于这种情况。如何纠正?任何帮助,将不胜感激。
注:如果您需要任何其他信息,请让我知道。
Product
public class Product
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductId { get; set; } //Uniquely identifies product
[Required, Index(IsUnique = true), MaxLength(50), Display(Name = "Product Name")]
public string ProductName { get; set; } //Product Name
[Required, Column(TypeName = "ntext"), Display(Name = "Product Description")]
public string ProductDesc { get; set; } //Product Description
[Required,Display(Name="Select Warehouse location")]
public int WarehouseId { get; set; }
[ForeignKey("WarehouseId")]
public virtual Warehouse warehouse { get; set; }
[Required,Display(Name="Category of the Product")]
public int CategoryId { get; set; } //Identifies product category
[ForeignKey("CategoryId")]
public virtual Category category { get; set; }
[Required,Display(Name="Select Supplier of this product")]
public int SupplierId { get; set; } //Identifies product supplier
[ForeignKey("SupplierId")]
public virtual Supplier supplier { get; set; }
[Required, Display(Name = "Quantity Per Unit")]
public int QuantityPerUnit { get; set; } //Product quantity per unit
[Required, Display(Name = "Unit Cost Price")]
public decimal UnitCostPrice { get; set; } // Product unit price
[Required, Display(Name = "Unit Selling Price")]
public decimal UnitSellingPrice { get; set; } // Unit Selling price
[Required, Display(Name = "Unit Weight in KG")]
public int UnitWeight { get; set; } // Product unit weight
[Display(Name = "Unit Size")]
public string UnitSize { get; set; } // Product unit size, S, M, L
[Display(Name = "Any discount on this product")]
public decimal Discount { get; set; } // Discount offered by supplier
[Required, Display(Name = "Unit in Stock")]
public int UnitInStock { get; set; } //Product units in stock
[Display(Name = "Unit in Order")]
public int UnitInOrder { get; set; } // units in order from supplier
[Display(Name = "Reorder Level")]
public int ReOrderLevel { get; set; } // Product margin for re-ordering
[Display(Name = "Note")]
public string Note { get; set; } // Some note for product
public bool Active { get; set; } //to mention if this product is being active/dis-continued by the company
[HiddenInput]
public DateTime? date_from { get; set; } //date when this product was added
[HiddenInput]
public DateTime? date_to { get; set; } //date when this product was discontinued by company
}
以上是产品类模型。我认为从产品分类模型本身我可以提取哪个产品由哪个供应商提供,以及由每个供应商提供的每个产品的分类?
我宁愿设计这个问题数据库优先。比代码优先更容易 –
产品是否属于单一类别?供应商是否以某种方式限制了产品/类别? – Dennis
@ Dennis是的,一个产品属于一个类别。 – user3132179