2013-06-11 3 views
1

나는 각각 사용자 정의 필드를 저장할 수있는 3 가지 모델/테이블을 가지고 있습니다. 제 3 모델은 CustomerProductStock입니다.여러 모델에 대한 사용자 정의 데이터 모델

어쨌든 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; } 
} 
+0

이 세 가지가 포함되어 있습니다은 다음 당신이 좋아하는 부분 클래스를 생성, 이제

namespace myPrj { public partial class Product { // auto generated class } } 

:

EF의 당신을 위해 다음과 같은 엔티티 클래스를 생성한다고 가정 모델? – maxs87

+0

엔티티 프레임 워크가 어떻게 처리하는지 잘 모르겠습니다. – ChaoticLoki

답변

0

당신이 할 수있는 네, 그러나 나는 현재 접근 방식이 더 낫다고 생각합니다. 어쨌든, 다른 속성 (및 아마도 메서드)을 포함하도록 클래스 중 하나를 확장해야합니다 -이 경우 다른 클래스의 속성.

이렇게하려면 부분 클래스를 만듭니다. 일부 클래스는 해당 엔티티 클래스 중 하나와 같은 어셈블리 이름과 동일한 어셈블리 이름을 사용합니다. 당신이 클래스 파크를 생성하지 못할 이유

namespace myPrj 
{ 
    public partial class Product 
    { 
     // your partial class. 
     // Add properties of other entity classes here 
     // and you'll have all of them within the Product entity class... 
    } 
} 
관련 문제