Linq2Sql 或 EF4 中的空间数据类型支持
有谁知道(最好是有参考)VS2010 版本的 LinqToSQL 或 EntityFramework v4 是否支持对 SQL 2008 空间数据类型的查询?
Does anyone know (ideally, with a reference), whether the VS2010 release of LinqToSQL or EntityFramework v4 will support queries over the SQL 2008 spatial data types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是让它在实体框架/LINQ to Entities 中工作的解决方法:
您可以使用数据库视图返回众所周知的文本(在查询中使用“geometry.ToString()”)或二进制。然后,一旦返回结果行,只需将字符串/二进制文件转换为 .NET 中的 SqlGeometry 对象即可。
以下是用于构建视图的示例查询,该视图将几何类型的“位置”字段转换为众所周知的文本字符串:
以下是查询具有包含众所周知的“位置”字段的结果实体的示例。 “地理”对象的文本或字符串表示形式:
另一件事是,您需要在存储过程中执行任何基于空间的查询,因为您不想将表中的所有数据提取到 .NET 中以便使用 LINQ 执行您自己的空间查询。
这并不像原生支持 SQL 空间类型那样优雅,但它可以让您同时运行实体框架和 SQL 空间。
Here's a workaround to get it working in Entity Framework / LINQ to Entities:
You can use a database View to return Well-Known-Text (using "geometry.ToString()" in the query) or Binary. Then once the resulting rows are returned, just convert the string/binary to a SqlGeometry object in .NET.
Here's a sample query used to build a View that converts a "Location" field of geometry type to a Well-Known-Text String:
Here's an example of querying the resulting entities that have a "Location" field that contains a Well-Known-Text or String representation of the "geography" object:
One additional thing, is you'll need to do any spatial based queries within Stored Procedures, since you don't want to pull ALL the data from the table into .NET in order to perform your own spatial query using LINQ.
This isn't an elegent as natively supporting SQL Spatial Types, but it'll get you running with Entity Framework and SQL Spatial simultaneously.
在 EF 4.0 中,您可以使用 自定义函数 并假装空间类型实际上是二进制类型。这是我正在考虑尝试并添加到 我的技巧系列。但到目前为止,即使是黑客攻击也尚未得到证实。 :(
至于直接支持,不幸的是 L2S 或 EF v4 都不支持 VS2010 时间范围内的空间类型。
Alex James
实体框架项目经理。
In EF 4.0 you might be able to hack something together using a combination of custom functions and pretending the spatial types are really Binary types. This is something that I am thinking of mucking around with and trying out and adding to my tips series. But as yet even the hack is unproven. :(
And as for direct support, unfortunately neither L2S or EF v4 will support spatial types in the VS2010 timeframe.
Alex James
Entity Framework Program Manager.
您当然也可以使用手写的表和列进行 Linq-to-SQL,并直接获取 SQL 空间类型。我在示例数据库上测试了以下内容(不要忘记包含对 System.SqlServer.Types 的引用和“使用
……
”
You can also definitely do Linq-to-SQL with hand-written tables and columns and get the SQL spatial types directly. I tested the following on a sample DB (dont' forget to include reference and 'using' to System.SqlServer.Types
...
...