SqlMetal cannot generate new foreign key associations to certain tables

109 Views Asked by At

My team are using SqlMetal to generate database classes from a SqlServer database. It works perfectly for all of our existing classes and foreign key associations but it's refusing to generate the code for a particular new foreign key association that we want to add. This key is from an audit table to a global event table detailing the time the audit record was created and the user it was created by. Many similar foreign key associations between other audit tables and this global "event" table exist in the system and SqlMetal generates code for those associations.

I've tried resolving this problem by:

  • Dropping and recreating the table
  • Removing the primary key
  • Creating a new identical table with a different name
  • Removing all other fields from the table
  • Dumping the indexes
  • Performing a fresh database build
  • Renaming the foreign key

None of the above seem to resolve the problem. However, SqlMetal does correctly generate code for foreign key associations from this table to some (but not all) other tables in the system. The association between these two tables would only generate when I altered the original create table script to include the foreign key association rather than running it (or a new equivalent table) in later. Unfortunately, we need to be able to deploy this change as a script to our existing production database so this isn't an option. I've seen a couple of articles and forum posts mentioning similar problems but none seem to give any solution or even an explanation.

0

There are 0 best solutions below