简体   繁体   中英

Unable to cast object of type 'System.DBNull' to type 'System.String' in Scaffold-DbContext .Net Core

I use the following method to use Databases:

Scaffold-DbContext "Server=[serverName] ; Database=[DatabaseName]; user id= [UserId] ; password = [Password];" 
        Microsoft.EntityFrameworkCore.SqlServer 
        -Project "[ProjectName]" -Force 
        -ContextDir "[DirectoryNameOutPut]\Context" 
        -OutputDir "[DirectoryNameOutPut]" 
        -UseDatabaseNames -NoPluralize

But in some databases, I get this error:

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

This error occurs after the Scaffold-DbContext command is written in the Package Manager Console and I press Enter and does not classify any of the tables.

What can I do to fix this error?

在此处输入图片说明

Add -Verbose flag to your Scaffold-DbContext to get more details.

Scaffold-DbContext "Server=[serverName] ; Database=[DatabaseName]; user id= [UserId] ; password = [Password];" 
        Microsoft.EntityFrameworkCore.SqlServer 
        -Project "[ProjectName]" -Force 
        -ContextDir "[DirectoryNameOutPut]\Context" 
        -OutputDir "[DirectoryNameOutPut]" 
        -UseDatabaseNames -NoPluralize
        -Verbose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM