views:

16

answers:

1

I'm trying to build a relatively simple game review site. There should be a 1-to-1 relationship between games and reviews (each review is for one game, and there will only ever be one review for a game). My tables are pretty simple. The relevant parts are:

Reviews Table:
ReviewID - int, primary key
Text - text
GameID - int, foreign key from Games Table

Games Table:
GameID - int, primary key
GameTitle - nvarchar(50)

EF4 keeps mapping it as a 1-to-many relationnship given the existence of a foreign key in Reviews. When I try to change it to 1-to-1 manually, I get the following error:

Error 1 Error 113: Multiplicity is not valid in Role 'Reviews' in relationship 'FK_Reviews_Games'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.

I'm not sure what the error is trying to say as the foreign key GameID in the Reviews table is the primary key of the Games table. Any ideas?

+1  A: 

I'm not sure what the error is trying to say as the foreign key GameID in the Reviews table is the primary key of the Games table.

Of course because it is NOT the primary key of the Review table and in order for EF to make a 1:1 association between Game and Review entities, it needs to be.
So, basically you need to get rid of the ReviewID on Review table and make GameID to be the primary key of the Review table and then EF will happily create a 1:1 for you.

Morteza Manavi