Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Issue: Power Tools: Wrong key mapping in the Reverse Engineer Code First [868]

$
0
0
Ok, my Database is made on the Brazil originally in the IBM Informix, and i trying to migrate to SQL Server, i've copy the structure data (table, primary and foreign keys) via SQL script, and i doing a .net console application to migrate the data, so the table and column names is not nice, and the relational keys are problematic, don't try understand what each table means.

So here is the thing; many columns are primary keys in the table one and consequently in the table two many columns are foreign keys, if the reverse engineer code first does not map correctly the primary keys or change the original database order of primary keys mapping, so the code first entity table mapping is wrong, and if you execute the application without change the key mapping to the correct form you will get an ModelValidation Exception, because the foreign key mapping does not match to the primary key mapping.

The wrong key map is on the tabel notes_alim, it's inverting the columns t.alim_versao, t.alim_tp_documento

i'm not certain but i think there other tables mapping with the same behavior

Comments: It looks like the reverse engineer code in System.Data.Entity.Design.dll assumes that the order of primary key members matches the order of the columns on the table. Thus, when the HasKey call is generated, the correct order of the primary key members is lost and gets out-of-sync with the order on the foreign keys. We should be able to work around this by making the HasForeignKey calls match the order of the referenced entity's HasKey call. This can be done in the Power Tools' T4 file.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>