それぞれがカスタム フィールドを格納できる 3 つの異なるモデル/テーブルがあります。私の 3 つのモデルはCustomer
Product
とStock
です。
CustomData
3 つのモデルすべてのカスタム データを処理できる単一のテーブルにマップされたモデルを作成する方法はありますか? 現在、モデルごとに個別のテーブル/モデルがあります。
顧客モデル:
[Table("Customer")]
public class Customer
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CustomerID { get; set; }
public string Prefix { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
public string Address { get; set; }
public string CountryID { get; set; }
[ForeignKey("CountryID")]
public virtual Country Country { get; set; }
public string City { get; set; }
[Display(Name = "Postcode")]
public string PostCode { get; set; }
//[RegularExpression(@"\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\b")]
public string Email { get; set; }
public string Remarks { get; set; }
[Display(Name = "Telephone")]
public string PhoneNumber { get; set; }
public ICollection<CustomCustomerProperty> CustomProperties { get; set; }
}
製品モデル:
[Table("Product")]
public class Product
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductID { get; set; }
public int ProductTypeID { get; set; }
public string ProductName { get; set; }
[ForeignKey("ProductTypeID")]
public virtual ProductType ProductType { get; set; }
public ICollection<CustomProductData> CustomProperties { get; set; }
}
カスタム製品モデルのプロパティ:
[Table("CustomProductData")]
public class CustomProductData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CustomPropertyID { get; set; }
public int CustomProductPropertyID { get; set; }
[ForeignKey("CustomProductPropertyID")]
public virtual CustomProductProperty CustomProductPropertyType { get; set; }
public int ProductID { get; set; }
[ForeignKey("ProductID")]
public virtual Product Product { get; set; }
public string PropertyValue { get; set; }
}