0

I read a lot of examples and tutorials about adding referential constraints but my designer just doesn't give me the FK I would need to select. I'm using model first and all my IDs are GUIDs.

These are the two entities:

enter image description here

These are the properties of their association:

enter image description here

And this is the "Referential Constraint Dialog":

enter image description here

As you can see: There is no FK to select as "Dependent Property"... In the database there is a FK column for that:

enter image description here

What am I doing wrong?

Thanx

SolarX
  • 1,873
  • 2
  • 18
  • 26

1 Answers1

1

Because your entity doesn't have any FK property. You must first create the property which will be used as your FK and select it in Dependent Property drop down (it shows only existing properties of dependent entity).

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • When I create an association in the designer, these properties aren't generated and I actually don't want to expose them as properties. – SolarX Sep 07 '11 at 08:44
  • In such case you don't have to do nothing. That is difference between [independent and foreign key associations](http://www.ladislavmrnka.com/2011/05/foreign-key-vs-independent-associations-in-ef-4/). – Ladislav Mrnka Sep 07 '11 at 08:55
  • I got the designer to generate the FK property by using "Add Association" instead of dragging the association from the toolbox. I marked setter and getter as private, so that it won't be exposed. Thank you!! – SolarX Sep 07 '11 at 09:00
  • 1
    Without a referential constraint, I got this error when just removing a child from its parent collection: "A relationship from the 'PresentationTemplatePresentationSection' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'PresentationSection' must also in the 'Deleted' state.". Therefore I need to referential constraint which is not created for and independent association. Am I right ?? – SolarX Sep 07 '11 at 09:05
  • 1
    No you are not. That is another problem. Referential constraint have nothing to do with this. The problem is that you have removed child form navigation property but in case of EF this only means you broke the connection between entities but you didn't delete the dependent entity = child still exists and is without required parent. You must delete the dependent entity or use [identifying relation](http://stackoverflow.com/questions/4922228/entity-framework-4-delete-object-from-entity-collection/4925040#4925040). – Ladislav Mrnka Sep 07 '11 at 09:21