实体框架6和空间数据 [英] Entity framework 6 and spatial data

查看:129
本文介绍了实体框架6和空间数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有具有空间数据类型的数据库。我使用数据库第一模型和实体框架6.0.2和.NET 4.5。当我尝试使用生成的类时,我收到以下错误:



指定的模式无效。错误:
由于类型Model.TypeB不可用,因此Name_FK1关系未加载。
以下信息可能有助于解决以前的错误:
类型Data.TypeB上的属性位置的属性类型为System.Data.Spatial.DbGeography,不能为映射到原始类型。



为使用空间类型的所有表列出相同的错误。 'Name_FK1'是外键关系。



我做错了什么?



感谢您的帮助。

解决方案

非常自豪:)



希望这有助于别人。所以,从上面的链接( http://msdn.microsoft.com/en-US/ data / dn469466 )有这样一行:


空间类(例如DbGeography,DbGeometry)已从
System.Data.Spatial => System.Data.Entity.Spatial


在我收到此错误之前:


由于IntakeModel.Location类型不可用,因此未加载IntakeModel.FK_Assignee_HomeLocation关系

以下信息可能有助于解决以前的错误:
类型ConsoleApplication3.Location上的属性Geo具有
属性类型为System.Data.Spatial.DbGeography '不能将
映射到原始类型。


我只需要在我的Location.cs文件中更改:

  public System.Data.Spatial.DbGeography Geo {get;组; 

为此:

  public System.Data.Entity.Spatial.DbGeography Geo {get;组; 

解决问题。感谢您发布该链接@Ricky Jones。


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.

解决方案

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.

这篇关于实体框架6和空间数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆