简体   繁体   English

无法将“System.DBNull”类型的对象转换为 Scaffold-DbContext .Net Core 中的“System.String”类型

[英]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'无法将“System.DBNull”类型的对象转换为“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.在包管理器控制台中写入Scaffold-DbContext命令并且我按Enter并且没有对任何表进行分类后,会发生此错误。

What can I do to fix this error?我能做些什么来修复这个错误?

在此处输入图片说明

Add -Verbose flag to your Scaffold-DbContext to get more details.-Verbose标志添加到您的Scaffold-DbContext以获取更多详细信息。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.InvalidCastException:无法将类型为System.DBNull的对象转换为类型为System.String的对象 - System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String' RowDataBound:从dataTable获取值! 无法将“System.DBNull”类型的对象强制转换为“System.String”类型 - RowDataBound : Getting value from dataTable ! Unable to cast object of type 'System.DBNull' to type 'System.String' Entity Framework Group BY 导致无法将“System.DBNull”类型的对象转换为“System.String”类型 - Entity Framework Group BY causing Unable to cast object of type 'System.DBNull' to type 'System.String' 获取所有产品时无法将类型为“System.DBNull”的 object 转换为类型“System.String” - Unable to cast object of type 'System.DBNull' to type 'System.String' On getting all Products 转换:无法将“System.DBNull”类型的对象转换为“System.String”类型 - Transformation: Unable to cast object of type 'System.DBNull' to type 'System.String' 如何修复无法将类型为“ System.DBNull”的对象转换为类型为“ System.String”的对象 - How can i fix Unable to cast object of type 'System.DBNull' to type 'System.String` 未以根身份连接时,无法将类型为“ System.DBNull”的对象转换为类型为“ System.String”的对象 - Unable to cast object of type 'System.DBNull' to type 'System.String' WHEN NOT CONNECTING AS ROOT 无法将“System.DBNull”类型的 object 转换为类型“System.String” - Unable to cast object of type 'System.DBNull' to type 'System.String` 如果默认情况下字符串为空,为什么我无法将类型为“ System.DBNull”的对象转换为类型为“ System.String”的对象? - If strings are nullable by default, why do i get Unable to cast object of type 'System.DBNull' to type 'System.String'.? db查询:一个字段可以是null,另一个不是“无法将'System.DBNull'类型的object转换为'System.String'类型” - db query: one field ok to be null, another not “Unable to cast object of type 'System.DBNull' to type 'System.String'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM