New Posts New Posts RSS Feed: One to one associations
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

One to one associations

 Post Reply Post Reply
Author
samir View Drop Down
Newbie
Newbie


Joined: 30-Mar-2011
Posts: 14
Post Options Post Options   Quote samir Quote  Post ReplyReply Direct Link To This Post Topic: One to one associations
    Posted: 24-May-2011 at 4:35pm
Hello.
 
Can anyone point me how to create one to one relationships using the Entity Framework designer (model first)? When I create this type of association Visual Studio disables the "Add foreign key properties to the 'xxx' entity', wich ends up in DevForce throwing erros like
 
'DevForce requires that foreign key columns be included in the model. This must be set when the EDMX is first created. If you are upgrading from DevForce 2009, you cannot use the old model and should recreate it using the Entity Framework for .NET 4.0.  The following associations were not set up with foreign key associations enabled: ....'
 
Thanks,
Samir
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 24-May-2011 at 5:13pm
Hi samir,
 
After creating the Association, you will need to add a Referential Constaint for this Association.
You will be able to add it in the Association Properties.
 
Regards,
   Silvio.
Back to Top
samir View Drop Down
Newbie
Newbie


Joined: 30-Mar-2011
Posts: 14
Post Options Post Options   Quote samir Quote  Post ReplyReply Direct Link To This Post Posted: 25-May-2011 at 7:29am
Hi Silvio, thanks for the quick response.
Let´s say my two entities are A and B, each with an Int32 Id property as entity key. To create the Referential Constraint I´ve created a property named AId (Int32) to my B entity and set the Referential Constraint as so:
Principal: A
Dependent: B
Principal Key: Id
Dependent Property: AId
I understand that from the database´s point of view this would allow more than one B entity to associate with the same A entity, which is why (I believe) DevForce throws this error:
Error 113: Multiplicity is not valid in Role 'B' in relationship 'AB'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.
Is setting the AId property to be an Entity Key the only way to make this work? Anyway, I set the AId to be an Entity Key and now B has two Entity Keys - Id and AId - but DevForce still gives me the same Error 113.
So I tried removing the Id property from the B Entity and now everything works.
Thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down