Entidad marco Asociación en modelo conceptual para relación uno a muchos

I have two entity CUSTOMER and ORDER..there is one to many relation from CUSTOMER to ORDER where CustomerID is primary key for customer and foreign key in ORDER..now I want to add customer name property from CUSTOMER entity in ORDER entity...I have copied this property and paste it in ORDER table and have added CUSTOMER table and map this property to the CUSTOMER table's same property..but when i trying to validate it vs giving me a Error that is

3024: Problem in mapping fragments starting at line 239:Must specify mapping for all key properties (ORDER.OrderID) of the EntitySet ORDER

preguntado el 01 de febrero de 12 a las 14:02

1 Respuestas

That is not possible in mapping. You cannot add property from Customer mesa en Order entity this way. Mapping properties from multiple tables to the same entity has very strict rules and it is not possible for this case.

You can expose customer's name in your Order class without defining it in the mapping. Create partial part of Order class and add custom computed property (non mapped):

public partial class Order
    public string CustomerName 
            // Customer is navigation property to Customer entity
            return Customer.Name;

This will require loading Customer con tu Order (eager loading) or using lazy loading. Also this property cannot be used in Linq-to-entities queries.

Respondido 01 Feb 12, 18:02

thanks a lot for your reply...i think you are telling about code-first approach...but i am doing database first approach and trying to do it in designer mode...if there is no any solution of this in db first i ll go for code-first - Anup

No I'm describing database first approach as well. Designer is not for defining all properties you need in your classes. Designer is only for defining mapping and mapping has its strict rules which you have violated by defining property in Order entity which is not mapped to Orders mesa. - Ladislav Mrnka

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.