简体   繁体   中英

Error Creating an Association between Views in Entity Framework EDMX

I have a project where I am using Views and Stored Procedures with EF5. I have an EDMX with the views in the designer and am trying to manually create the associations between the PK and FK across 2 views, when doing so I first get this error:

Error 5 Error 3027: No mapping specified for the following EntitySet/AssociationSet - vw_borrowervw_borrower_extension .

Then if I do table mapping on the association and select the pk and fk I receive this error:

Error 5 Error 3007: Problem in mapping fragments starting at lines 309, 351:Column(s) [borrower_fk] are being mapped in both fragments to different conceptual side properties.

In the one view the primary key name is borrower_pk and in the related view the foreign key is named borrower_fk.

Any help would be much appreciated.

Thanks!

You must use Foreign key association and map it as constraint . At the moment you are most probably trying to map independent association which is not possible in EDMX because independent associations are mapped to their database counterparts. Your database doesn't have these relations so they are not described in SSDL (the part of EDMX describing the storage model) and because of that cannot be mapped this way.

Still this is pretty dangerous operation if your entities are not read-only (= you are using stored procedures mapped for insert, update and delete oprations). EF decides order of modification operations from SSDL. If your SSDL doesn't know about the relation EF will not know that parent entity must be inserted prior to child entity, that children must be deleted prior to parent, etc. I'm not sure how does EF order operation when it doesn't have any referential constraints but from some former answer it looks like it simply processes entities in alphabetical order.

What I ended up doing was in the EDMX remove the field that was the foreign key and then when creating the association let it add the foreign key properties to the entity. This got rid of the error. However this isn't an ideal solution. Can't wait for EF6 for better code-first stored procedure support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM