EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

EfCore3 DbGeography SqlGeography

Open mmisnerms opened this issue 5 years ago • 11 comments

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

mmisnerms avatar Jan 08 '20 17:01 mmisnerms

I will investigate, for now set

Settings.DisableGeographyTypes=true;

sjh37 avatar Jan 08 '20 20:01 sjh37

@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 avatar Jan 08 '20 22:01 sjh37

Released in v3.1.1

sjh37 avatar Jan 09 '20 09:01 sjh37

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.

mmisnerms avatar Jan 09 '20 20:01 mmisnerms

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());

sjh37 avatar Jan 09 '20 20:01 sjh37

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}\")]");

mmisnerms avatar Jan 09 '20 21:01 mmisnerms

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

sjh37 avatar Jan 09 '20 21:01 sjh37

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.

sjh37 avatar Jan 09 '20 21:01 sjh37

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.

mmisnerms avatar Jan 09 '20 21:01 mmisnerms

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

sjh37 avatar Jan 11 '20 09:01 sjh37

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

sjh37 avatar Jan 11 '20 09:01 sjh37