Print Page | Close Window

One to one associations

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2713
Printed Date: 30-Jul-2026 at 2:24am


Topic: One to one associations
Posted By: samir
Subject: One to one associations
Date 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



Replies:
Posted By: sbelini
Date 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.


Posted By: samir
Date 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!



Print Page | Close Window