LINQ to SQL 设计器和地理数据类型
我在将表格加载到设计器中时遇到一些问题。 我收到以下错误。
一个或多个所选项目包含设计器不支持的数据类型
我是否正确地假设是表中使用的地理类型导致了此错误?
非常感谢任何指点。
I am having a few problems loading a table into the designer.
I get the following error.
One or more selected items contain a data type that is not supported by the designer
Would I be correct in assuming it is the geography type used in the table that is causing this error?
Any pointers much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要更正此错误:
2. 将视图从服务器资源管理器/数据库资源管理器拖到设计器上。
或参阅这篇文章 缺失的 Linq to SQL Spatial,本文提供有关如何在 Linq to SQL 中使用 SQL Server 空间数据类型(地理和几何)的提示和技巧
To correct this error:
2.Drag the view from Server Explorer/Database Explorer onto the designer.
or see this article The Missing Linq to SQL Spatial,This article provides hints and hacks on how to use the SQL Server spatial data types -Geography and Geometry- in Linq to SQL
检查下面的文章/答案以了解详细信息:
SqlGeography 和 Linq to Sql
是否可以使用SqlGeography使用 Linq to Sql?
Linq to SQL 不支持空间类型。支持并不是“不太好”——而是根本不存在。
您可以将它们作为 BLOB 读取,但不能通过简单地更改 Linq to SQL 中的列类型来做到这一点。您需要使用 CAST 语句在数据库级别更改查询以将列作为 varbinary 返回。您可以通过添加计算的 varbinary 列在表级别执行此操作,Linq 会很乐意将其映射到 byte[]。
Check below article / answer for the detail :
SqlGeography and Linq to Sql
Is it possible to use SqlGeography with Linq to Sql?
Spatial types are not supported by Linq to SQL. Support is not "not great" - it's nonexistent.
You can read them as BLOBs, but you can't do that by simply changing the column type in Linq to SQL. You need to alter your queries at the database level to return the column as a varbinary, using the CAST statement. You can do this at the table level by adding a computed varbinary column, which Linq will happily map to a byte[].
我有一个项目(当然是一个小项目),它逐渐对空间类型提出了新的要求。我决定看看从 LINQ 升级到 SQL 到实体框架有多么容易。
我花了不超过30分钟。在开始之前,请确保您有源代码管理备份。
Install-Package EntityFramework -Version {pick one}
.dbml
文件metadata=res://*/;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;初始目录=MyDataBase; Integrated Security=True'
Insert/DeleteOnSubmit
和 EF 的Add/Remove
或Add/RemoveRange
方面的差异。事务范围的工作方式可能不同(考虑使用context.Database.BeginTransaction而不是事务范围)。就是这样。这比我预期的要容易得多,现在我可以毫无技巧地使用空间类型。
I have a project (a small one, granted) that grew to have new requirements for spatial types. I decided to see how easy it would be to upgrade to entity framework from LINQ to SQL.
It took me no more than 30 minutes. Make sure you have a source control backup before you start.
Install-Package EntityFramework -Version {pick one}
.dbml
file(s)metadata=res://*/;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS; Initial Catalog=MyDataBase; Integrated Security=True'
Insert/DeleteOnSubmit
and EF'sAdd/Remove
orAdd/RemoveRange
. Transaction scopes may work differently (consider usingcontext.Database.BeginTransaction
instead of transaction scopes).That's it. It was much easier than I expected and now I can use the spatial types without any trickery.