1
나는 각각 사용자 정의 필드를 저장할 수있는 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._%+-][email protected](?:[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; }
}
이 세 가지가 포함되어 있습니다은 다음 당신이 좋아하는 부분 클래스를 생성, 이제
:
EF의 당신을 위해 다음과 같은 엔티티 클래스를 생성한다고 가정 모델? – maxs87
엔티티 프레임 워크가 어떻게 처리하는지 잘 모르겠습니다. – ChaoticLoki