【问题标题】:Entity Framework Core Scaffolding "Could not find type mapping for column with data type 'hierarchyid'. Skipping column"实体框架核心脚手架“找不到数据类型为‘hierarchyid’的列的类型映射。跳过列”
【发布时间】:2020-06-18 15:44:29
【问题描述】:

我正在试验 .net 核心、实体框架和 sqlserver,我认为 hierarchyID 是我尝试建模的完美数据类型。但是当我搭建数据库时,EFC 无法映射层次结构。

Could not find type mapping for column 'dbo.ingredient.hierarchy_id' with data type 'hierarchyid'. Skipping column.
Could not scaffold the primary key for 'dbo.ingredient'. The following columns in the primary key could not be scaffolded: hierarchy_id.
Unable to generate entity type for table 'dbo.ingredient'.
Could not find type mapping for column 'dbo.ingredient_location.ingredient_id' with data type 'hierarchyid'. Skipping column.
Could not find type mapping for column 'dbo.locations.location' with data type 'geography'. Skipping column.
Could not find type mapping for column 'dbo.pantry_ingredient.ingredient_id' with data type 'hierarchyid'. Skipping column.

我应该放弃使用该数据类型的想法还是有解决方法?

我寻找了一些解决方案,但它们都需要手工编写脚手架,我目前没有足够的信心这样做

【问题讨论】:

  • hierarchyid 似乎没有得到 EF Core 的良好支持。有关一些提示,请参阅 SO 问题和答案Entity Framework Core hierarchyid
  • 感谢您的回复,我决定通过定义父 id 字段来使用自定义层次结构

标签: .net sql-server entity-framework scaffolding hierarchyid


【解决方案1】:

您需要安装 nuget Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite 以支持几何功能。

【讨论】:

  • 谢谢 alessandro,但它也是由层次结构 id 数据类型引起的,虽然我正在使用的实体框架的当前版本无法解决这一问题
【解决方案2】:

我遇到了同样的问题。 我的项目使用了所有 Microsoft 库版本 3.1.4 和 MySQL.Data 版本 8.0.22 和 MySQL.Data.EntityFrameworkCore 版本 8.0.22 幸运的是,我之前有一个非常相似的项目构建,它使用 Microsoft 库版本 3.1.4 和 MySQL.Data 版本 8.0.20 和 MySQL.Data.EntityFrameworkCore 版本 8.0.20 一旦我将 MySQL 库切换回版本 8.0.20 脚手架工作得很好。

我猜只是有冲突的库或版本 8.0.22 有一些错误。

【讨论】:

  • 在我的情况下,我遇到了日期时间数据类型的问题
  • 我遇到了同样的问题,我将版本返回到 8.0.20 并且可以正常工作,是否已经确定了一个错误?现在我发现 8.0.20 版本将 tinyint (1) 类型映射到 byte 而不是像 8.0.22 版本那样映射到 bool,我将不得不选择一个并在 scafold 之后进行更正
猜你喜欢
  • 2021-01-10
  • 2014-12-13
  • 2018-02-16
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
相关资源
最近更新 更多