locked
Unused foreign keys in edmx RRS feed

  • Question

  •  

    I was just wondering if this is correct behaviour.  I have an entity model with two tables with a 1-1 mapping, and a FK between the two.  If I delete the FK from the model or one of the tables when I next compile I get the following error:

     

    Error 3013: Problem in Mapping Fragment(s) starting at line(s) (256, 375, 384, 393): Missing table mapping: Foreign key constraint 'FK_gmAlerts_gmTransactions1' from table gmAlerts (AlertTransID) to table gmTransactions (TransID): no mapping specified for the table gmTransactions.
     C:\devwork\tmp\efmodel\efmodel\Monitor.edmx

     

    The only way I have found to cure the problem is to delete the AssociationSet relating to this FK from the EntityContainer portion of the edmx file, which doesn't seem right to me.  I would have thought that I would be able to have unsed parts of the storage model

     

    Am I missing something?

     

    Cheers

     

    Stephen,

    Sunday, July 6, 2008 2:22 AM

Answers

  • I'm sure some of the guys who are better experts in the mapping than I will jump in and provide more details / corrections, but my understanding of this is that while it is possible to leave out parts of the storage model, some parts of the model are much more significant to maintaining data integrity than others.  Just as you can't really leave out a non-nullable column which doesn't have a default value (because if you were to create a new entity and save it, then the system wouldn't supply the required value), you also need to be careful about relationships in the database.  If you make changes to a set of entities and there are relationships to that set, then you may well need to make changes to the association set (in the form of modifying foreign key values on a table in the DB).  If you don't map these foreign keys, then the system doesn't know how to reason about the model in a way that will maintain your data integrity.

     

    - Danny

     

    Sunday, July 6, 2008 3:34 AM

All replies

  • I'm sure some of the guys who are better experts in the mapping than I will jump in and provide more details / corrections, but my understanding of this is that while it is possible to leave out parts of the storage model, some parts of the model are much more significant to maintaining data integrity than others.  Just as you can't really leave out a non-nullable column which doesn't have a default value (because if you were to create a new entity and save it, then the system wouldn't supply the required value), you also need to be careful about relationships in the database.  If you make changes to a set of entities and there are relationships to that set, then you may well need to make changes to the association set (in the form of modifying foreign key values on a table in the DB).  If you don't map these foreign keys, then the system doesn't know how to reason about the model in a way that will maintain your data integrity.

     

    - Danny

     

    Sunday, July 6, 2008 3:34 AM
  •  

    Sounds reasonable.  I was just assuming that I could remove the table (or FK) I was not interested in, add the foreign key fields as scalar properties and just supply the values and just let the underlying db worry about data integrity and any constraints there may be. 

     

    Stephen.

    Sunday, July 6, 2008 2:35 PM