Entity framework 6 and spatial data
Asked Answered
S

3

7

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.

Sidran answered 22/12, 2013 at 12:3 Comment(0)
F
23

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.

Flashback answered 24/1, 2014 at 21:20 Comment(1)
But System.Data.Entity.Spatial is in EntityFramework.dll. You're telling me I have to add a reference to Entity Framework in my POCO Entities class library!?Facial
A
5

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

Alcina answered 22/12, 2013 at 16:46 Comment(3)
This is th elink how to upgrade application. I have new application and I add EF 6.0 using NuGet and then I add new Data - ADO.NET Entity Data Model. And this is not working fro me.Sidran
I had the exact same error message you did, I would make sure that you don't have System.Data.Entity.dll referenced, and do step 3, which is to delete the code generation template and click on the designer and choose Add code generation item... thats the only thing I can offer because it worked for me.Alcina
I have tried, but failed. When I am trying to add EF 6 I have only EF 5.x DbContext Generator option. There is no option for EF 6.x DbContext Generator. I am 100% that I installed EF 6 and not EF 5.Sidran
R
1

This problem was caused because you created a EF 5.x DbContext Generator for a EF 6.0 edmx to solve this problem you just need to delete the old DbContext Generator and create a new one with EF 6.0 DbContext Generator.

This worked fine for me.

Reube answered 14/7, 2014 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.