/// <summary> /// Selects the rows that match the given condition. /// </summary> /// <typeparam name="T">The table type.</typeparam> /// <param name="connection">The connection to query on.</param> /// <param name="columnFilter">The type whose properties will filter the result.</param> /// <param name="whereExpr">The where condition to use for this query.</param> /// <param name="transaction">The transaction to use for this query.</param> /// <param name="buffered">Whether to buffer the results in memory.</param> /// <param name="commandTimeout">Number of seconds before command execution timeout.</param> /// <returns>The rows that match the given condition.</returns> public static IEnumerable <T> GetDistinct <T>(this IDbConnection connection, Type columnFilter, Expression <Func <T, bool> > whereExpr, IDbTransaction transaction = null, bool buffered = true, int commandTimeout = 30) where T : class { ISqlQueries <T> queries = ExtraCrud.Queries <T>(); WhereConditionData <T> data = queries.Compile(whereExpr); IEnumerable <T> list = queries.GetDistinct(connection, columnFilter, data.WhereCondition, data.Param, transaction, buffered, commandTimeout); return(list); }
/// <summary> /// Deletes the rows that match the given condition. /// </summary> /// <typeparam name="T">The table type.</typeparam> /// <param name="connection">The connection to query on.</param> /// <param name="whereExpr">The where condition to use for this query.</param> /// <param name="transaction">The transaction to use for this query.</param> /// <param name="commandTimeout">Number of seconds before command execution timeout.</param> /// <returns>The number of deleted rows.</returns> public static int DeleteList <T>(this IDbConnection connection, Expression <Func <T, bool> > whereExpr, IDbTransaction transaction = null, int commandTimeout = 30) where T : class { ISqlQueries <T> queries = ExtraCrud.Queries <T>(); WhereConditionData <T> data = queries.Compile(whereExpr); int count = queries.DeleteList(connection, data.WhereCondition, data.Param, transaction, commandTimeout); return(count); }
/// <summary> /// Selects the rows with the given keys. /// </summary> /// <typeparam name="T">The table type.</typeparam> /// <typeparam name="KeyType">The key type.</typeparam> /// <param name="connection">The connection to query on.</param> /// <param name="whereExpr">The where condition to use for this query.</param> /// <param name="transaction">The transaction to use for this query.</param> /// <param name="buffered">Whether to buffer the results in memory.</param> /// <param name="commandTimeout">Number of seconds before command execution timeout.</param> /// <returns>The keys that match the given condition.</returns> public static IEnumerable <KeyType> GetKeys <T, KeyType>(this IDbConnection connection, Expression <Func <T, bool> > whereExpr, IDbTransaction transaction = null, bool buffered = true, int commandTimeout = 30) where T : class { ISqlQueries <T> queries = ExtraCrud.Queries <T>(); WhereConditionData <T> data = queries.Compile(whereExpr); IEnumerable <object> keys = queries.GetKeysKeys(connection, data.WhereCondition, data.Param, transaction, buffered, commandTimeout); if (typeof(KeyType) == typeof(long)) { if (keys.Any()) { Type type = keys.First().GetType(); if (type == typeof(int)) { keys = keys.Select(k => (object)(long)(int)k); } } } IEnumerable <KeyType> castedKeys = keys.Select(k => (KeyType)k); return(castedKeys); }
/// <summary> /// Initializes a new instance of the <see cref="DataAccessObject{T}"/> class. /// </summary> /// <param name="connectionString">The connectionString<see cref="string"/></param> /// <param name="buffered">The buffered<see cref="bool"/></param> public DataAccessObject(string connectionString, bool buffered = true) { Connection = new SqlConnection(connectionString); Buffered = buffered; Queries = ExtraCrud.Queries <T>(); }
/// <summary> /// Initializes a new instance of the <see cref="DataAccessObject{T}"/> class. /// </summary> /// <param name="connectionString">The connectionString<see cref="string"/></param> public DataAccessObject(string connectionString) { Connection = new SqlConnection(connectionString); Queries = ExtraCrud.Queries <T>(); }