实体框架不从SQL Server存储过程中获得的结果空间数据类型 [英] Entity Framework not getting Spatial type data in result from Sql Server stored procedure

查看:179
本文介绍了实体框架不从SQL Server存储过程中获得的结果空间数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的实体框架6 .NET 4.5 。我有一个选择,并返回数据的存储过程。 一个返回列是一个地理类型即可。
在Visual Studio 2015年,我右击.edmx文件,单击更新模型从数据库...。这一行动得到我的存储过程,并创建了一个复杂类型storeprocedurename_Result的。所有列在复杂类型对象的表示,除了地理类型即可。搜索结果
同时我的表的一个也有地理类型,但该表successfuly检索与地理柱,它是正常。所以,我可以猜到地理类型是EF支持和工作正常。结果
但是我不知道为什么它不产生这种类型,我中产生的复杂类型。结果
我试着手动添加公共System.Data.Entity.Spatial.DbGeography COL_NAME {搞定;组; }但它得到的结果为空。结果
。对于我曾尝试执行的SQL Server Management studion过程的记录,该列是目前。因此,其对EF结束的问题不是DB结束。结果
我已经搜查,有一对夫妇的这样的问题,但似乎没有人能回答这些问题。结果
我不能够理解这个问题的答复。结果
http://www.scriptscoop.net/t/2758a3668fde/geography-column-returned-in-stored-procedure-not-shown-in-entity- fram.html 搜索结果
,它是一个在计算器结果
https://stackoverflow.com/questions/28592085/geography-column-returned-in-stored-procedure-未显示的功能于实体框架-AUTO# = 结果
,因为他不,我不要说,在评论上述问问题的人使用了一种变通方法认为你可以自动获得地理类型。因为当你查看模型浏览器,它说不支持的结果。为了解决这个问题,我的存储过程的地理类型转换为通过[pro_GeoLocation] .STAsText字符串()作为pro_GeoLocationPoint。然后,我使用正则表达式在我的C#代码,以获得长期和纬度。但是,这是不是一个好的选择,必须有一个解决方案。结果

I'm using Entity Framework 6 with .Net 4.5. I have a stored procedure that selects and returns data. One of the return columns is a geography type. In Visual Studio 2015, I right click the .edmx file, click "Update Model From Database...". This action gets my stored procedure and creates a complex type of storeprocedurename_Result. All the columns are represented in the complex type objects except the geography type.

At the same time one of my table also have Geography type but that table is retrieved successfuly with the geography column and it is functioning properly. So, i can guess geography type is supported in EF and is working.
But i don't know why it is not generating that type for me in the complex type generated.
I tried manually adding public System.Data.Entity.Spatial.DbGeography col_name { get; set; } but it got null in results.
For the record i have tried executing the procedure in Sql Server management studion and that column is present there. So, its problem on EF end not DB end.
I have searched and got a couple of questions like these, but it seems no one is able to answer them.
I was not able to understand the response on this question.
http://www.scriptscoop.net/t/2758a3668fde/geography-column-returned-in-stored-procedure-not-shown-in-entity-fram.html

and it is one on stackoverflow
https://stackoverflow.com/questions/28592085/geography-column-returned-in-stored-procedure-not-shown-in-entity-framework-auto#=
The person asking above question has used a workaround as he says in comment "No. I don't think you can automatically get the geography type. Because when you view the results in the model browser it says "Not supported". To get around this issue, my stored proc converts the geography type to a string via [pro_GeoLocation].STAsText() as pro_GeoLocationPoint. Then I use a regex in my C# code to get the long and lat." But this is not a good option and there must be a solution to this.

推荐答案

好吧......结果
,因为我是期待(看到以前的帖子是这样)没有回答这个问题,所以现在当我已经解决了这个问题,我将临客分享这让我地理对象的解决方案。结果
结果
我试了很多东西,尝试了很多的解决方案,我放弃了从EDMX很多次我的程序和SP进入。而重新创建,但一切都是徒劳!结果
比什么工作是如此简单......下面我刚刚打开EDMX的联系,比开放模式的浏览器之后,在模型浏览器转到您的复杂类型认定中是缺少列中,右键单击添加 - >标性财产>地理。并精确给它的名字是由存储过程retured。结果
多数民众赞成它,保存更改并运行代码,你必须正确地得到您的数据因为我收到。结果我很奇怪,为什么EF无法获得的数据,并在获取功能/ SP的列信息就提到EDM类型不支持。 Strage!
结果
结果
编号: http://www.scriptscoop.net/t/7c1ed5a0f89e/entity-framework-5-function-import-with-spatial-data。 HTML

Alright...
As i was expecting (seeing previous posts like this) there was no answer to this problem, so now when i have solved the problem, i will linke to share the solution which got me the geography object.

I tried many things and tried many solution, i dropped my procedure and SP entry from edmx many times. And re created but all in vain!
Than what worked was so simple... following the link below i just opened edmx, than open model browser, in model browser go to your complex type defination which is missing the column, right click add->scalar property->geography. And give it the name precisely which is retured by stored procedure.
Thats it, save the changes and run your code, you must get your data properly as i am getting.
I am wondering why EF was not able to get the the data and on getting column information of the function/SP it mentioned EDM type unsupported. Strage!

Ref: http://www.scriptscoop.net/t/7c1ed5a0f89e/entity-framework-5-function-import-with-spatial-data.html

这篇关于实体框架不从SQL Server存储过程中获得的结果空间数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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