TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
208 stars 53 forks source link

Feature EnableSchemaFolders creates entities with missing namespaces #134

Closed audacity76 closed 2 years ago

audacity76 commented 4 years ago

If schema folders are enabled, the generated InversePropertyAttribute of the navigation properties (which use nameof) fail to find entities from different schemas / namespaces. Also, the DbContext namespaces aren't correct. It is missing the base namespace. The generated namespace looks like: using Schema = .Schema;

DbContext and Entities need to declare all referenced schemas like: using Schema = Base.Namespace.Schema;

tonysneed commented 3 years ago

@audacity76 Is this still happening? Can you provide an example?

tonysneed commented 3 years ago

Please re-open if needed.

AceCoderLaura commented 3 years ago

Yeah, I'm getting this one as well. You should be able to recreate it just by having two tables that are in different database schemas reference each other with a foreign key.

AceCoderLaura commented 3 years ago

Yeah, I poked through the code and found the line where the issue is occurring.

https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars/blob/19444cf6928df9a5b20586ae125ee98af8f41042/src/EntityFrameworkCore.Scaffolding.Handlebars/HbsCSharpEntityTypeGenerator.cs#L150

The issue is that GetProperties doesn't return navigation properties (see: GetProperties documentation).

tonysneed commented 3 years ago

@AceCoderLaura Would you be able to submit a PR with a fix?

AceCoderLaura commented 3 years ago

@AceCoderLaura Would you be able to submit a PR with a fix?

Yeah, I've got a fix for it, I was going to write some tests too but I haven't gotten around to it yet. I should get to it later today.

AceCoderLaura commented 3 years ago

Looks like I'd have to turn the tests upside down to modify or add table schemas. I might just submit the fix.

tonysneed commented 2 years ago

@AceCoderLaura Thank you for your contribution! Sorry it took so long for me to circle back to it.