locked
Not enforcing foreign key constraint and navigation properties RRS feed

  • Question

  • I have two tables in my database, that are linked by a foreign key. I set the property "Enforce Foreign Key Constraint" to "No" in SQL Server for that foreign key.
    Now the data model generated by Entity Framework contains a navigation property, and I'm not happy with it.

    myEventEntity.CardReference = { EntityKey = new EntityKey("ProjectEntities.CardEntitySet", "Id", cardId) }

    If I do that, I can get an exception when the Id I'm giving (cardId) is the Id of an entity loaded in the context, and in the deleted state. It should work though, because SQL Server does not enforce the foreign key in this case. Is there a workaround I could use here?

    Thank you

    Flavien
    Tuesday, June 2, 2009 12:26 PM