Shared/Kernelx.MO2EFCore/Cmpts/EFMOI/Core/EFDatabaseCommand.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Kernelx.Cmpts.MOI;
using Kernelx.Data;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kernelx.Cmpts.EFMOI.Core
{
internal class EFDatabaseCommand : IDatabaseCommand
{
private Lazy<DbConnection> _dbConnection;
public EFDatabaseCommand(EFModelibContextBase context)
=> _dbConnection = new Lazy<DbConnection>(()=>context.Database.GetDbConnection());
private DbCommand CreateCommand( string cmdText, IList<ParameterObject> cmdParms = null, CommandType cmdType = CommandType.Text)
{
var conn = _dbConnection.Value;
if(conn.State != ConnectionState.Open)
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = cmdText;
cmd.CommandType = cmdType;
if(cmdParms != null)
{
foreach (var parm in cmdParms)
{
var p = cmd.CreateParameter();
p.ParameterName = parm.Name;
p.Value = parm.Value;
if (parm.ColType.HasValue)
p.DbType = parm.ColType.Value;
if (parm.Direction.HasValue)
p.Direction = parm.Direction.Value;
cmd.Parameters.Add(p);
}
}
return cmd;
}
public object ExecuteScalar(string cmdText, IList<ParameterObject> cmdParms = null, CommandType cmdType = CommandType.Text)
=>CreateCommand(cmdText,cmdParms,cmdType).ExecuteScalar();
public int ExecuteSqlCommand(string cmdText, IList<ParameterObject> cmdParms = null, CommandType cmdType = CommandType.Text)
=> CreateCommand(cmdText, cmdParms, cmdType).ExecuteNonQuery();
public DataSet GetDataSet(string cmdText, IList<ParameterObject> cmdParms = null, CommandType cmdType = CommandType.Text)
{
using (var cmd = CreateCommand(cmdText, cmdParms, cmdType))
{
var result = new DataSet();
using (var reader = cmd.ExecuteReader())
后面还有 30 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
