42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
namespace LaaProductionWeb.Data
|
|
{
|
|
using LaaProductionWeb.Data.Interfaces;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class SQLCommand
|
|
{
|
|
private readonly SqlClient sqlClient;
|
|
private readonly IDictionary<string, object> parameters;
|
|
|
|
public SQLCommand(SqlClient sqlClient, string commandText)
|
|
{
|
|
this.sqlClient = sqlClient;
|
|
this.CommandText = commandText;
|
|
this.parameters = new Dictionary<string, object>();
|
|
}
|
|
|
|
internal string CommandText { get; }
|
|
|
|
internal IReadOnlyDictionary<string, object> Parameters
|
|
=> this.parameters as IReadOnlyDictionary<string, object>;
|
|
|
|
public SQLCommand AddParameter(string name, object value)
|
|
{
|
|
this.parameters[name] = value ?? DBNull.Value;
|
|
|
|
return this;
|
|
}
|
|
|
|
public T FirstOrDefault<T>(Func<ISqlReader, T> expression)
|
|
=> this.sqlClient.FirstOrDefault(this, expression);
|
|
|
|
public int ExecuteNonQuery()
|
|
=> this.sqlClient.ExecuteNonQuery(this);
|
|
|
|
public IEnumerable<T> ExecuteReader<T>(Func<ISqlReader, T> expression)
|
|
=> this.sqlClient.ExecuteReader(this, expression);
|
|
}
|
|
}
|