实体框架核心脚手架“找不到数据类型为‘hierarchyid’的列的类型映射。跳过列”

Red*_*Red 3 .net sql-server entity-framework scaffolding hierarchyid

我正在试验 .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.
Run Code Online (Sandbox Code Playgroud)

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

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

小智 8

我有同样的问题。我的项目使用了所有 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 之后进行更正 (2认同)

小智 6

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