Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework 6 and spatial data

I have database with spatial data types. I use database first model and entity framework 6.0.2 and .NET 4.5. When I am trying to use the generated classes I get following error:

Schema specified is not valid. Errors: The relationship 'Name_FK1' was not loaded because the type 'Model.TypeB' is not available. The following information may be useful in resolving the previous error: The property 'Position' on the type 'Data.TypeB' has a property type of 'System.Data.Spatial.DbGeography' which cannot be mapped to a primitive type.

The same error is listed for all tables where I use spatial type. The ‘Name_FK1’ is foreign key relation.

What am I doing wrong?

Thank you for your help.

like image 268
UrosP Avatar asked Dec 22 '13 12:12

UrosP


People also ask

What is difference between Entity Framework 5 and 6?

EF5 is built into the core of . NET 4.5, whereas EF6 has been shifted out, and is open source. This means that you must add the new EF6 assemblies to all of the relevant projects in the solution, in particular the entry project. This means that you must remove assembly System.

Which is spatial data?

Spatial data comprise the relative geographic information about the earth and its features. A pair of latitude and longitude coordinates defines a specific location on earth. Spatial data are of two types according to the storing technique, namely, raster data and vector data.

What is Srid in geometry?

A spatial reference identifier (SRID) is a unique identifier associated with a specific coordinate system, tolerance, and resolution.

What is NetTopologySuite?

NetTopologySuite (NTS) is a spatial library for . NET. EF Core enables mapping to spatial data types in the database by using NTS types in your model.


2 Answers

I fixed it! Very proud of myself :)

Hope this helps somebody else. So, from the link above (http://msdn.microsoft.com/en-US/data/dn469466) there is this line:

Spatial classes (e.g. DbGeography, DbGeometry) have moved from System.Data.Spatial => System.Data.Entity.Spatial

Before I was getting this error:

The relationship 'IntakeModel.FK_Assignee_HomeLocation' was not loaded because the type 'IntakeModel.Location' is not available. The following information may be useful in resolving the previous error: The property 'Geo' on the type 'ConsoleApplication3.Location' has a property type of 'System.Data.Spatial.DbGeography' which cannot be mapped to a primitive type.

I just had to change this in my Location.cs file:

public System.Data.Spatial.DbGeography Geo { get; set; }

To this:

public System.Data.Entity.Spatial.DbGeography Geo { get; set; }

Problem solved. Thanks for posting that link @Ricky Jones.

like image 190
user1477388 Avatar answered Nov 06 '22 09:11

user1477388


I followed the instructions on the following link, which caused other problems I needed to solve, but it did fix my spatial issue.

http://msdn.microsoft.com/en-US/data/dn469466

like image 44
Ricky Jones Avatar answered Nov 06 '22 10:11

Ricky Jones