sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
699 stars 230 forks source link

Sqlite Code Generation fails #834

Open statler opened 3 months ago

statler commented 3 months ago

I am trying to reverse engineer the attached Sqlite db with the given config. It fails with an uninformative warning. I tried debugging the T4, but that bails out after creating the configs for the primitives. Latest version. Any ideas?

Blankv120.zip

sjh37 commented 3 months ago

Hi Statler, I'm currently on holiday with the family, I'll be back in the country on Monday.

statler commented 3 months ago

OK - so it runs correctly if you use the debug T4 template function in VS, but fails if you try and run it on save.

statler commented 3 months ago

OK, so it runs, but still generates incorrect configurations. Basically, if a class has multiple FKs to the same table, it will only add the first relationship . I expect that this line is the culprit var constraints = fkList.Select(x => x.FkSchema + "." + x.ConstraintName).Distinct();

Because in the Sqlite config, the schema is identical, and the constraintname is built using the current table and FK Primary key ID, which is also the same. I expect this is a mistake, and the constraintname should include the local property.

statler commented 1 month ago

Are you planning on fixing this?

sjh37 commented 1 month ago

Sorry @statler Yes I am. I'll take a look at this now.

sjh37 commented 1 month ago

The issue of multiple foreign keys to the same table has been fixed. Thanks for the heads-up on where to look. Foreign keys will have a different name though and will need to be changed in your code after the first run. Download the latest EF.Reverse.POCO.v3.ttinclude