How to resolve: error while attempting to add FK

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
extrakun
Posts: 22
Joined: Wed 20 Apr 2011 06:02

How to resolve: error while attempting to add FK

Post by extrakun » Fri 10 Jun 2011 07:56

I keep getting this error while attempting to add a FK in table.

Code: Select all

Properties referred by the Principal Role ASPNET_USERS
 must be exactly identical to the key of the EntityType MyApp.Models.Store.ASPNET_USERS
 referred to by the Principal Role in the relationship constraint for Relationship MyApp.Models.Store.FK_UserInfo_AspnetUsers. 
Make sure all the key properties are specified in the Principal Role.
What exactly does this means?

The table schema is

Code: Select all

ASPNETUSERS 

Column                 Type
-------                --------
UserID (PK)                 GUID
...
UserInfoID             NUMBER


USERINFO

Column                 Type
-------                --------
ID (PK)                      NUMBER

I am attempting to add a 1 to 1 relationship from ASPNETUSERS to USERINFO, using UserInfoID to ID. UserInfoID from ASPNETUSERS is not a key.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 10 Jun 2011 08:38

Entity Framework treats the one-to-one relationship as a relationship between two Entity Keys.
You can create a view that performs a join of User and UserInfo tables, and add this view as an entity to your model.
As an alternative you can go into Entity Splitting.

Post Reply