How to map an entity to multiple tables with different keys in Entity Framework 5 RRS feed

  • General discussion

  • I am trying to create a view like entity in Conceptual model using Northwind Database.

    The view should have properties from Orders and Customers.

    By creating a One to One association and Mapping, both to Orders table, I achieved half of it. But how to add properties from Customers table into my View entity. Because If I add properties then there should be mapping to Customers. As there is no orderId key property in Customers, validation becomes failure.

    Error 3024: Problem in mapping fragments starting at line 268:

    Must specify mapping for all key properties (UserEntities.OrderID) of the EntitySet UserEntities.

    Is there any way to map a custom entity in Conceptual model to Orders and Customer table of Northwind from Storage Model in Entity Framework 5.

    • Changed type Antony Joseph A.V Thursday, December 20, 2012 4:41 AM
    • Changed type Antony Joseph A.V Saturday, December 22, 2012 1:36 PM I didn't find any proper solution for my question and I am not ready to compromise with workarounds.
    Thursday, December 20, 2012 4:16 AM

All replies

  • Hi Antony,

    Welcome to the MSDN forum.

    You are required to create the same entity in SSDL and MSL to map the entity you created in conceptual model. In addition, the database must have the corresponding tables/views. If you have the view already in database, you can check the steps on this page to map the entity to this view: http://smehrozalam.wordpress.com/2009/08/12/entity-framework-creating-a-model-using-views-instead-of-tables/

    Have a nice day.

    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 21, 2012 8:10 AM
  • Hello Alexander,

    thanks for your quick and kind reply.

    so custom view is not possible in EF?.

    I think it is one of the basic requirement, that accessing SQL Server for creating the views(that require changes periodically, according to application), is not feasible.

    And If we talk about using DefiningQuery and QueryView, then the same can be achieved by writing query from application and there will never be a chance of losing data on updating model from Database.

    Is there any other workaround, OR any future plan of integrating, CustomView editing using EF designer other than Query.

    Friday, December 21, 2012 10:03 AM