PomeloFoundation / Pomelo.EntityFrameworkCore.MySql

Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
MIT License
2.68k stars 382 forks source link

Unable to cast object of type 'System.DBNull' to type 'System.String' #1725

Open J031PC opened 1 year ago

J031PC commented 1 year ago

Steps to reproduce

Sorry, I don't understand any English..

Upgrade a project from .net6 to .net7, when executing this query it gives me an error.

var vm = await _context.Users
    .Where(e => e.Id == request.Id)
    //.ProjectTo<GetUserDetailVm>(_mapper.ConfigurationProvider)
    SingleOrDefaultAsync(cancellationToken);

The issue

I think it is related to MySqlConnector:

System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.

Further technical details

MySQL version: 5.7.33 Operating system: Mac M1 Pomelo.EntityFrameworkCore.MySql version: 7.0.0-alpha.1

Other details about my project setup: The project use Mediatr (commands/queries) for ddd and clear architecture.

mguinness commented 1 year ago

Your English is good. Please use code blocks instead of posting screenshots. See https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1571 regarding your issue.