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
707 stars 228 forks source link

EfCore3 DbGeography SqlGeography #571

Open mmisnerms opened 4 years ago

mmisnerms commented 4 years ago

I was using Microsoft.SqlServer.Types with EF 6.4.

I am now migrating to EFCore 3.1 and unable to resolve the generated types for geography.

Spatial.DbGeography Microsoft.SqlServer.Types.SqlGeography

sjh37 commented 4 years ago

I will investigate, for now set

Settings.DisableGeographyTypes=true;
sjh37 commented 4 years ago

@mmisnerms This has now been correctly implemented. Grab the latest EF.Reverse.POCO.v3.ttinclude file.

Install the following NuGet package:

Install-Package Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite

Re-save your <database>.tt file to regenerate.

Also have a read of this wiki page

sjh37 commented 4 years ago

Released in v3.1.1

mmisnerms commented 4 years ago

Thank you for addressing this so quickly!

The new release resolved the type not found problem with Spatial.DbGeography in my entities.

But SP return model is still trying to use Microsoft.SqlServer.Types.SqlGeography.

I changed to NetTopologySuite.Geometries.Point to get past the type issue.

Now I am getting

"The property 'column' is of type 'Point' which is not supported by current database provider. Either change the property CLR type or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'."

Also, Point type is geometry X,Y,Z. I am looking for sql server geography type which has Longitude and Latitude.

sjh37 commented 4 years ago

When opening your database, you need to add in the action UseNetTopologySuite

optionsBuilder.UseSqlServer(
    @"Data Source=(local);Initial Catalog=YourDatabase;Integrated Security=True",
    x => x.UseNetTopologySuite());
mmisnerms commented 4 years ago

Thank you. That worked.

It is still generating Microsoft.SqlServer.Types.SqlGeography for stored procedure return model properties.

I also notice a syntax issue with string interpolation $ in the tt file. I am using tangible t4 editor extension.

column.Attributes.Add($"[Display(Name = \"{column.DisplayName}\")]");
sjh37 commented 4 years ago

ok, that bit Microsoft.SqlServer.Types.SqlGeography is still a bug. Thanks for letting me know.

sjh37 commented 4 years ago

What's wrong with the Display name? Both forms are acceptable:

[DisplayName("Product name")]
[Display(Name = "Product name")]

Or have I missed something else?

I checked with the stackoverflow page, and both are acceptable, with [Display(Name = "Product name")] being localisable.

mmisnerms commented 4 years ago

It may just be me. The syntax of the tt file itself. VS is complaining that the $ string interpolation is not correct.

So if I change the tt file to column.Attributes.Add(string.Format("[Display(Name = \"{0}\")]", column.DisplayName)); VS no longer complains about syntax.

sjh37 commented 4 years ago

Updated the source code to stop tangible t4 complaining about that line. This will be in the next version.

sjh37 commented 4 years ago

Kept open for Microsoft.SqlServer.Types.SqlGeography for stored procedure return model properties.