mysql bit转bool失败,带有Mysql的EF Core无法将BIT(1)设置为布尔值

本文介绍了一位开发者在尝试使用.NET Core CLI从现有数据库生成DB类时遇到的问题:数据库中的bit(1)字段未被正确识别为布尔类型,而是被识别为short类型。文章提供了详细的解决方案,包括所需的NuGet包及命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am trying to generate DB classes from the existing database (DB first) through. Net core CLI.

The DB was perfectly working with EF5 and .net4.5 but after migrate to EF core the bit(1) field is not scaffolding as bool instead it is generating as short.

Also tried with TinyInt(1) but no luck.

Technology Stack -

.Net core - 2.2

MySql.Data.EntityFrameworkCore (8.0.15)

MySQl Connector Net 8.0.13

innodb_version 8.0.13

解决方案

First you need to add this packages from Nuget:

MySql.Data.EntityFrameworkCore

Microsoft.EntityFrameworkCore.Design

then run this command :

Scaffold-DbContext "server=localhost;port=3306;user=root;password=mypass;database=sakila" MySql.Data.EntityFrameworkCore -OutputDir model -f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值