ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.21k stars 299 forks source link

How do you use spatial types when scaffolding using the NuGet package? #2432

Closed alowdon closed 4 months ago

alowdon commented 4 months ago

Really sorry if I've missed something obvious here but I'm having problems getting spatial types to work when scaffolding a model from a dacpac.

We have an existing scaffolding process using dotnet ef dbcontext scaffold which is working fine but requires the DB project to be published to a SQL Server DB before scaffolding from that. I've been experimenting with using the ErikEJ.EntityFrameworkCore.SqlServer.Dacpac to scaffold directly from the dacpac to avoid that interim step, which would be amazing if we can get it working. However, unfortunately although spatial types are generated correctly using our existing scaffolding, they are missing from the scaffolded model when generating from the dacpac.

We're currently using EF Core 6, so I'm using version 6.0.8 of the NuGet package. I've seen mention of efpt.config.json and have tried to introduce one with UseSpatial: true in order to enable spatial types but to no avail.

Please can you let me know if it is possible to use spatial types with this setup (using dotnet ef dbcontext scaffold with ErikEJ.EntityFrameworkCore.SqlServer.Dacpac as the provider), and if so, how? Many thanks in advance!

Note: I know there is the option of using the erikej.efcorepowertools.cli tool, but unfortunately we have various customisations we would have to rewrite in order to do so, so ideally I'm hoping to use as much of our existing process as possible, and therefore using the NuGet package rather than the tool.

ErikEJ commented 4 months ago

Wonder if spatial works with the CLI and a .dacpac? Maybe you can confirm? Remember to enable the type mappings in the config file.

Assume you DbContext has .UseSpatial?

alowdon commented 4 months ago

Thank you for such a quick reply!

I've been digging some more and I've discovered that our spatial columns are actually computed, and this suggests that we'll need to manually add those computed columns, so I can look at doing that. I assume that maybe because we have no other spatial columns that's why it didn't detect/output the UseNetTopologySuite config in the OnConfiguring method when the DbContext was generated from the NuGet package, which made me think spatial types weren't being recognised correctly.

Sorry for taking your time, and thanks again for your reply; I'll close this for now as I think the immediate issue is explained by the above.

ErikEJ commented 4 months ago

Cool, thanks for confirming.

If you like my free tools, I would be very grateful for a rating or review on Visual Studio Marketplace or even a one-time or monthly sponsorship