简体   繁体   English

实体框架6和空间数据

[英]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. 我使用数据库优先模型和实体框架6.0.2和.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. 错误:由于类型'Model.TypeB'不可用,因此未加载关系'Name_FK1'。 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. 以下信息对于解决先前的错误可能有用:类型为“ Data.TypeB”的属性“位置”具有属性类型为“ System.Data.Spatial.DbGeography”,该属性类型无法映射为原始类型。

The same error is listed for all tables where I use spatial type. 对于使用空间类型的所有表,都会列出相同的错误。 The 'Name_FK1' is foreign key relation. “ Name_FK1”是外键关系。

What am I doing wrong? 我究竟做错了什么?

Thank you for your help. 谢谢您的帮助。

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: 因此,从上面的链接( http://msdn.microsoft.com/en-US/data/dn469466 ),有以下行:

Spatial classes (eg DbGeography, DbGeometry) have moved from System.Data.Spatial => System.Data.Entity.Spatial 空间类(例如DbGeography,DbGeometry)已从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. 由于类型'IntakeModel.Location'不可用,因此未加载关系'IntakeModel.FK_Assignee_HomeLocation'。 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. 以下信息对于解决先前的错误可能很有用:类型为“ ConsoleApplication3.Location”的属性“ Geo”具有属性类型为“ System.Data.Spatial.DbGeography”,该属性类型无法映射为原始类型。

I just had to change this in my Location.cs file: 我只需要在Location.cs文件中更改此设置即可:

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. 感谢您发布该链接@Ricky Jones。

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 http://msdn.microsoft.com/zh-CN/data/dn469466

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. 造成此问题的原因是,您为EF 6.0 edmx创建了EF 5.x DbContext生成器以解决此问题,您只需要删除旧的DbContext生成器并使用EF 6.0 DbContext Generator创建一个新的DbContext生成器。

This worked fine for me. 这对我来说很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM