none
How to map multiple entities on the same table RRS feed

  • Question

  • Hi, I have two tables, logins and admins mapped to entity model. Now I would like to add new entity, which will include just some of properties of those two entities. But if I create a new entity and map properties to columns in those two tables I get error

    Error 1 Error 3033: Problem in Mapping Fragment starting at line 215: EntitySets 'MyEntitySet' and 'Admins' are both mapped to table 'Admins'. Their Primary Keys may collide.
     L:\Users\Radovan.Culak\Desktop\EntitiesTest\EntitiesTest\Test.edmx 216 15 EntitiesTest

    How can I handle that?
    Thanks
    Tuesday, June 30, 2009 10:12 AM

All replies

  • Hi,
    You can create a DefiningQuery for the new entity that includes the fields you need of both logins and admins tables (instead of mapping multiple entities to the same table which can cause primary key conflicts).
    In such way you won't have the conflict that the error you get indicate (Primary Keys may collide).
    The DefiningQuery is a SSDL element that is used to create a view over the database. That view is read only but
    you can create stored procedures and map them to your entity in order to enable CUD operations.
    You can read more about DefningQuery here:
    http://blogs.microsoft.co.il/blogs/gilf/archive/2008/05/14/how-why-use-definingquery-element.aspx
    I hope it helps.
    Gil Fink
    Tuesday, June 30, 2009 5:26 PM