【发布时间】:2021-06-12 05:52:43
【问题描述】:
我刚刚将我的应用程序从 .NET Core 2.1 迁移到 .NET Core 3.1 ,但是在那之后,我在使用过的地方都收到了错误 dbContext.Database.GetDbConnection.
这里我使用命名空间 System.Data.SqlClient。那么如何更改代码以使用 .NET Core 3.1 我在下面给出了代码。
当我尝试更改 Microsoft.Data.SqlClient 时,错误无法从 Microsoft.Data.SqlClient.SqlConnection 转换为 'string ' 将显示,请提供帮助
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
//using Microsoft.Data.SqlClient;
using System.Linq;
public UserRepository(dbContext db) : base(db)
{
_db= db;
}
var conn = (SqlConnection)_db.Database.GetDbConnection();
DataTable dtMissingDates = new DataTable();
SqlParameter parUserId = new SqlParameter("@UserId", userId);
SqlParameter parDepots = new SqlParameter("@DepotNo", depono);
SqlParameter parDepartment = new SqlParameter("@DepartmentID", department);
SqlParameter parDate = new SqlParameter("@DateTo",attdate);
SqlHelper.FillDatatable(conn
, CommandType.StoredProcedure
, StoredProcedureConstants.GET_DEPOT_MISSING_ATT_POPUP
, dtMissingDates
, MTSGOConstants.DEFAULT_COMMAND_TIME_OUT
, parUserId
, parDepots
, parDepartment
,parDate);
谢谢 波尔
【问题讨论】: