77 lines
3.8 KiB
C#
77 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Kit.Helpers.SqlHelperAbstract
|
|
{
|
|
|
|
public interface ISqlHelper
|
|
{
|
|
void ExecuteNonQuery(RequestParams requestParams);
|
|
object ExecuteScalar(RequestParams requestParams);
|
|
TResult ExecuteScalar<TResult>(RequestParams requestParams);
|
|
IEnumerable<TEntity> ExecuteSelectMany<TEntity>(RequestParamsSelect<TEntity> requestParams);
|
|
IEnumerableWithPage<TEntity> ExecuteSelectManyWithPage<TEntity>(RequestParamsSelect<TEntity> requestParams);
|
|
IEnumerableWithOffer<TEntity> ExecuteSelectManyWithOffer<TEntity>(RequestParamsSelect<TEntity> requestParams);
|
|
}
|
|
|
|
public static class SqlHelper
|
|
{
|
|
#region ExecuteNonQuery
|
|
|
|
public static void ExecuteNonQuery(this IConnectionString connectionString, string sql, bool isStoredProcedure,
|
|
bool withStrictSyntax = false, IEnumerable<KeyValuePair<string, object>> parameters = null, IEnumerable<CustomType> customTypes = null)
|
|
{
|
|
var requestParams = new RequestParams(connectionString, sql, isStoredProcedure,
|
|
withStrictSyntax, parameters, customTypes);
|
|
connectionString.GetSqlHelper().ExecuteNonQuery(requestParams);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ExecuteScalar
|
|
|
|
public static object ExecuteScalar(this IConnectionString connectionString, string sql, bool isStoredProcedure,
|
|
bool withStrictSyntax = false, IEnumerable<KeyValuePair<string, object>> parameters = null, IEnumerable<CustomType> customTypes = null)
|
|
{
|
|
var requestParams = new RequestParams(connectionString, sql, isStoredProcedure,
|
|
withStrictSyntax, parameters, customTypes);
|
|
return connectionString.GetSqlHelper().ExecuteScalar(requestParams);
|
|
}
|
|
|
|
public static TEntity ExecuteScalar<TEntity>(this IConnectionString connectionString, string sql, bool isStoredProcedure,
|
|
bool withStrictSyntax = false, IEnumerable<KeyValuePair<string, object>> parameters = null, IEnumerable<CustomType> customTypes = null)
|
|
{
|
|
var requestParams = new RequestParams(connectionString, sql, isStoredProcedure,
|
|
withStrictSyntax, parameters, customTypes);
|
|
return connectionString.GetSqlHelper().ExecuteScalar<TEntity>(requestParams);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ExecuteSelectMany
|
|
|
|
public static IEnumerable<TEntity> ExecuteSelectMany<TEntity>(this IConnectionString connectionString, string sql, bool isStoredProcedure,
|
|
bool withStrictSyntax = false, IEnumerable<KeyValuePair<string, object>> parameters = null, IEnumerable<CustomType> customTypes = null,
|
|
params Action<IDataRecordSpecified, IList<TEntity>>[] converters)
|
|
{
|
|
var requestParams = new RequestParamsSelect<TEntity>(connectionString, sql, isStoredProcedure,
|
|
withStrictSyntax, parameters, customTypes, converters);
|
|
return connectionString.GetSqlHelper().ExecuteSelectMany(requestParams);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ExecuteSelectManyWithPage
|
|
|
|
public static IEnumerableWithPage<TEntity> ExecuteSelectManyWithPage<TEntity>(this IConnectionString connectionString, string sql, bool isStoredProcedure,
|
|
bool withStrictSyntax = false, IEnumerable<KeyValuePair<string, object>> parameters = null, IEnumerable<CustomType> customTypes = null,
|
|
params Action<IDataRecordSpecified, IList<TEntity>>[] converters)
|
|
{
|
|
var requestParams = new RequestParamsSelect<TEntity>(connectionString, sql, isStoredProcedure,
|
|
withStrictSyntax, parameters, customTypes, converters);
|
|
return connectionString.GetSqlHelper().ExecuteSelectManyWithPage(requestParams);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |