Entity Framework Error 3002 / 3003 - Inheritance / key mapping issue
I have a data model as follows:
A Customer has Products and Payment Methods. Each Product can be assigned any or all of the Customer's Payment Methods, with one set as default.
Foreign Keys are:
Customer.CustomerId => Product.CustomerId
Customer.CustomerId => PaymentMethod.CustomerId
Product.ProductId => ProductPaymentMethod.ProductId
PaymentMethod.PaymentMethodId => ProductPaymentMethod.PaymentMethodId
I want to customise this model for presentation purposes, Customer to have a collection of Payment Methods and a collection of Products. Products to have a collection of ProductPaymentMethods which inherit from PaymentMethod.
I deleted the association between PaymentMethod and ProductPaymentMethod, added an inheritence from PaymentMethod to ProductPaymentMethod and deleted PaymentMethodId from ProductPaymentMethod.
This is now my model:
When I save the model or build the project I get 2 errors:
Error 3002: Problem in mapping fragments starting at line 226:Potential runtime violation of table ProductPaymentMethod's keys (ProductPaymentMethod.ProductPaymentMethodId): Columns (ProductPaymentMethod.ProductPaymentMethodId) are mapped to EntitySet PaymentMethods's properties (PaymentMethods.ProductPaymentMethodId) on the conceptual side but they do not form the EntitySet's key properties (PaymentMethods.PaymentMethodId).
and
Error 3003: Problem in mapping fragments starting at line 226:All the key properties (PaymentMethods.PaymentMethodId) of the EntitySet PaymentMethods must be mapped to all the key properties (ProductPaymentMethod.ProductPaymentMethodId) of table ProductPaymentM开发者_JS百科ethod.
What am I doing wrong?
EDIT: Having done some further Googling, I have found several solutions, most of which don't quite fit this scenario. Most talk about inheritance requiring a 1-1 not 1-many relationship. However, because of the Customer to Product 1-many relationship, the model requires a 1-many between PaymentMethod and ProfilePaymentMethod. Is it not possible to do what I am attempting?
My only answer to this so far is to have some manually created POCO classes for presentation and a Mapper class to turn my data entity into a presentation entity
精彩评论