在使用Entity Framework6.4.4和.NET 6在数据库中存储DbGeography类型的数据时,我收到以下错误:

不存在从对象类型Microsoft.SqlServer.Types.SqlGeography到已知托管提供程序本机类型的映射.

使用最新版本的Microsoft.SqlServer.Types:160.1000.6.

堆栈跟踪:

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
 ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details.
 ---> System.Data.Entity.Core.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details.
 ---> System.ArgumentException: 不存在从对象类型Microsoft.SqlServer.Types.SqlGeography到已知托管提供程序本机类型的映射.
   at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed)
   at System.Data.SqlClient.MetaType.GetMetaTypeFromType(Type dataType)
   at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
   at System.Data.SqlClient.SqlParameter.get_SqlDbType()

将数据保存到数据库时出错.(EF SaveChanges())

推荐答案

您可以使用我的替代提供程序,同样的概念也将适用于即将推出的EF 6.5提供程序-Microsoft.EntityFramework.SqlServer

https://www.nuget.org/packages/ErikEJ.EntityFramework.SqlServer

Csharp相关问答推荐

C#中的两个线程之间读写浮点类型

更新数据库中的对象失败,原因是:Microsoft. EntityFrame Core. GbUpdateConcurrencyResponse'

.NET最小API映射将T参数列表为[FromQuery]

下拉图片点击MudBlazor

如何使用while循环实现异常处理

如何在Visual Studio代码中更改大括号模式{},用于C#语言

WPF DataGrid中的三维数据

C#使用TextFieldParser读取.csv,但无法使用";0";替换创建的列表空条目

Swagger没有显示int?可以为空

GODOT 4向C#中的字符串参数发送信号以等待

为什么Azure函数(独立工作进程)索引失败?使用Azure App配置的CosmosDbTrigger绑定失败,未解析为值

MSI无法将快捷方式添加到启动文件夹

是否可以在Entity Framework Core中使用只读 struct 作为拥有实体?

错误:此版本的Visual Studio无法打开以下项目

如何对特定异常使用Polly重试机制?

当`JToken?`为空时?

为什么我的属性即使没有显式地设置任何[必需]属性,也会显示验证?

如何对列表<;列表>;使用集合表达式?

使用Try-Catch-Finally为API端点处理代码--有什么缺点?

从具有泛型类型约束的类继承-Blazor