How to use Spatial Data Types in asp.net vnext with EF 7?
Asked Answered
A

3

11

in vnext, using Entity Framework 7 (https://github.com/aspnet/EntityFramework) how to use Spatial Data types (e.g. DbGeography) in model (code-first method) to save points, shapes etc. when creating model for a table.

e.g.

public DbGeography gps_points {get; set;}

I'm unable to use DbGeography.


Update:

Confirmed, this feature is not yet available in EF7, but may be available in future versions.

to track any changes see:

https://github.com/aspnet/EntityFramework/issues/242

https://github.com/aspnet/EntityFramework/issues/1100

Aceto answered 19/11, 2014 at 3:48 Comment(4)
Very broad question. Have you tried anything yet? Are you having problems getting this to work?Sadden
I'm unable to use DbGeography for a column in creating model for table using code first method in entity framework. this works for asp.net 4 and ef 6, have this feature supported in ef alpha 7 or beta ?Aceto
Possible duplicate of Entity Framework Core: Type Udt is not supported on this platform. (Spatial Data - Geography)Regatta
@Eli Since you asked your question almost three years after this was asked, I'm pretty sure you should be removing your own duplicate question rather than flagging this one.Fayalite
I
2

Referring to your own issue at the github repository of Entity Framework, there seems no implementation, yet. As the milestone was set to "Backlog" it seems that this issue won't be resolved in the near future.

If you do not need to process your data geographically on database-side (e.g., search in a bounding box or intersections), you can save your data as Well-known text. This can be easily converted to a database geometry type, if EF7 supports spatial data in the future.

Be aware of the string length limits of your database, since WKT can get quiet long for complex shapes.

Iasis answered 27/11, 2014 at 8:20 Comment(3)
thanks for the comment. i hope in future versions this feature will be implemented soon.Aceto
Our team hopes so, too.Iasis
Could you show a code excerpt of how to use Well-known text?Stodder
S
0

You need to add a reference to System.Data.Entity.Spatial. I don't think it is now included by default under the EF reference, hence the reason you cannot use DbGeography.

Remember, everything is plug and play!

Samons answered 25/11, 2014 at 11:7 Comment(1)
Thanks for the help, but i didn't find any nuget package for this. as in vnext we can only add nuget packages not any dll directly as reference or dependency.Aceto
R
0

Support for spatial types was introduced in EF5. However, in EF5 spatial types are only supported when the application targets and runs on .NET 4.5.

Starting with EF6 spatial types are supported for applications targeting both .NET 4 and .NET 4.5.

the Microsoft SQL Server provider depends on some additional low-level libraries that may need to be installed.

Prerequisites for spatial types with Microsoft SQL Server

SQL Server spatial support depends on the low-level, SQL Server-specific types SqlGeography and SqlGeometry. These types live in Microsoft.SqlServer.Types.dll assembly, and this assembly is not shipped as part of EF or as part of the .NET Framework.

When Visual Studio is installed it will often also install a version of SQL Server, and this will include installation of the Microsoft.SqlServer.Types.dll.

If SQL Server is not installed on the machine where you want to use spatial types, or if spatial types were excluded from the SQL Server installation, then you will need to install them manually. The types are included in the SQL Server Feature Packs, and different assemblies exist for SQL Server 2008 and SQL Server 2012.

Rima answered 27/11, 2014 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.