我正在 .NET Core 中开发一个控制台应用程序,用于在数据库中读/写,使用与我之前的应用程序(针对 Web,用 ASP.NET MVC 编写)相同的代码(稍作更改)。
\n\n但是,当我查询数据库时,程序(正在运行)抛出无效的强制转换异常
\n\n\n\n\nSystem.InvalidCastException:\'无法将\'Microsoft.Data.SqlClient.SqlCommand\'类型的对象强制转换为\'System.Data.SqlClient.SqlCommand\'。\'。
\n
但这些命令在我的网络应用程序中运行没有问题。
\n\n有人能帮我解决这个问题吗?
\n\n一份 .csproj文件:
\xe2\x80\xa6 \n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <TargetFramework>netcoreapp2.1</TargetFramework>\n <StartupObject></StartupObject>\n </PropertyGroup>\n\xe2\x80\xa6\n <ItemGroup>\n\xe2\x80\xa6 \n <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />\n <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />\n <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />\n <PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0" />\n\xe2\x80\xa6 \n </ItemGroup>\nRun Code Online (Sandbox Code Playgroud)\n\n我在中配置应用程序的Main例程:Program.cs
using System;\nusing System.IO;\nusing Microsoft.EntityFrameworkCore;\nusing Microsoft.EntityFrameworkCore.SqlServer;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.DependencyInjection;\nusing Newtonsoft.Json;\nusing System.Collections.Generic;\n\xe2\x80\xa6 \n var optionsBuilder = new DbContextOptionsBuilder<fmDataContext>();\n\n optionsBuilder\n .UseSqlServer(connectionString, providerOptions => providerOptions.CommandTimeout(60));\n\n using (fmDataContext context = …Run Code Online (Sandbox Code Playgroud) 我正在 ASP.NET MVC 中编程,在网页 (.cshtml) 中我有如下文本输入区域:
\n\n<td>\n <input type="text" value="@p.QtdVendida" asp-for="@p.QtdVendida" data-key="@p.id" id="@("p_QtdVendida" + p.id.ToString())" />\n</td>\n<td>\n <input type="text" value="@p.QtdBonus" asp-for="@p.QtdBonus" data-key="@p.id" id="@("p_QtdBonus" + p.id.ToString())" />\n</td>\nRun Code Online (Sandbox Code Playgroud)\n\n如何防止列表自动使用以前的输入文本(例如来自其他会话)打开,并且始终在表第一行的文本输入中打开,即使我正在编辑第二行\xe2\x80\ xa6出现?如果我单击列出的其中一个元素,它只会更改第一行\xe2\x80\xa6 中的输入区域
\n\ntype="text"我在表中的所有文本输入 ( ) 中都遇到同样的问题。
你可以帮帮我吗?
\n\n非常感谢。
\n