关于数据模型结构的建议

时间:2017-04-06 13:23:48

标签: asp.net-mvc entity-framework database-design

我正在使用ASP.Net MVC 5练习,并且我正在尝试构建原型事件目录。我从基本布局开始,改编自Contoso大学教程,但我想开始开发更复杂的数据模型,但是我不确定开发模型的最佳方法,具体来说,每个列表可以有不同的定价选项。

我目前的数据模型是;

供应商

 public class Vendor
{
    public int ID { get; set; }
    [Required]
    [Display(Name = "Company Name")]
    [StringLength(50, ErrorMessage = "Company name cannot be longer than 50 characters.")]
    public string CompanyName { get; set; }
    [Required]
    [Display(Name = "First Name")]
    [StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
    public string ContactFirstName { get; set; }
    [Required]
    [Display(Name = "Last Name")]
    [StringLength(50, ErrorMessage = "Last name cannot be longer than 50 characters.")]
    public string ContactLastName { get; set; }
    [Required]
    [Display(Name = "Address")]
    public string Address { get; set; }
    [Required]
    [Display(Name = "Address Line 2")]
    public string AddressLine2 { get; set; }
    [Required]
    public string Region { get; set; }
    [Required]
    public string City { get; set; }
    [Required]
    public string Postcode { get; set; }
    [Required]
    [Display(Name = "Email Address")]
    public string Email { get; set; }
    [Required]
    [Display(Name = "Phone Number")]
    public string Phone { get; set; }
    [Display(Name = "Twitter @username")]
    public string TwitterHandle { get; set; }
    [Display(Name = "Facebook URL")]
    public string FacebookURL { get; set; }
    [Required]
    [Display(Name = "Active Vendor?")]
    public Boolean ActiveStatus { get; set; }

    public virtual ICollection<Listing> Listings { get; set; }
}

编目

public class Listing
{
    public int ListingID { get; set; }
    public int CategoryID { get; set; }
    public int VendorID { get; set; }
    [Required]
    [Display(Name = "Listing Name")]
    public string ListingName { get; set; }
    [Required]
    [Display(Name = "Listing Description")]
    public string ListingDesc { get; set; }
    [Required]
    [Display(Name = "Maximum Capacity")]
    public int Capacity { get; set; }
    [Required]
    [DataType(DataType.Currency)]
    [Display(Name = "Price Per Guest")]
    public decimal PricePerGuest { get; set; }
    [Required]
    public string Address { get; set; }
    [Display(Name = "Address Line 2")]
    public string Address2 { get; set; }
    [Required]
    public string City { get; set; }
    [Required]
    public string Postcode { get; set; }

    public virtual Category Category { get; set; }
    public virtual Vendor Vendor { get; set; }
}

分类

 public class Category
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int CategoryID { get; set; }
        public string CategoryName { get; set; }
        public string CategoryDescription { get; set; }

        public virtual ICollection<Listing> Listings { get; set; }
    }

理想情况下,我想在清单表中添加一个名为“固定价格”的新属性,为供应商提供按客户价格或固定价格列出的选项,并非全部供应商可以按每位客人的价格定价服务。

是一个单独的表格,其定价选项足以进一步发展吗?

P.S - 我还没有开始正确地格式化实体,因此为什么类别缺少验证等等。

1 个答案:

答案 0 :(得分:0)

Price(货币)和IsFixedPrice(位)代替PricePerGuest

感谢@Nikhil Vartak的回答