/// <summary>
        /// Returns a list entities of type T.
        /// </summary>
        /// <param name="connection">Sql Connection</param>
        /// <param name="adapter">ISqlAdapter for getting the sql statement</param>
        /// <param name="sql">The where clause</param>
        /// <param name="parameters">Parameters of the where clause</param>
        /// <param name="transaction">The transaction to run under, null (the default) if none</param>
        /// <param name="commandTimeout">Number of seconds before command execution timeout</param>
        /// <param name="fromCache">Cache the query.</param>
        /// <returns>True if records are deleted</returns>
        private static async Task <IEnumerable <T> > GetListAsync <T>(this IDbConnection connection, ISqlAdapter adapter, string sql, object parameters, IDbTransaction transaction = null, int?commandTimeout = null, bool fromCache = false) where T : class
        {
            var type      = typeof(T);
            var tinfo     = TableInfoCache(type);
            var selectSql = adapter.GetListQuery(tinfo, sql);

            return(await connection.QueryAsync <T>(selectSql, parameters, transaction, commandTimeout : commandTimeout));
        }
示例#2
0
        /// <summary>
        /// Returns the first matching T.
        /// </summary>
        /// <param name="connection">Sql Connection</param>
        /// <param name="adapter">ISqlAdapter for getting the sql statement</param>
        /// <param name="sql">The where clause</param>
        /// <param name="parameters">Parameters of the where clause</param>
        /// <param name="transaction">The transaction to run under, null (the default) if none</param>
        /// <param name="commandTimeout">Number of seconds before command execution timeout</param>
        /// <param name="fromCache">Cache the query.</param>
        /// <returns>True if records are deleted</returns>
        private static T GetFirst <T>(this IDbConnection connection, ISqlAdapter adapter, string sql, object parameters, IDbTransaction transaction = null, int?commandTimeout = null, bool fromCache = false) where T : class
        {
            var type      = typeof(T);
            var tinfo     = TableInfoCache(type);
            var selectSql = adapter.GetListQuery(tinfo, sql);

            return(connection.QueryFirstOrDefault <T>(selectSql, parameters, transaction, commandTimeout: commandTimeout));
        }
示例#3
0
        /// <summary>
        /// Returns a list entities of type T.
        /// </summary>
        /// <param name="connection">Sql Connection</param>
        /// <param name="adapter">ISqlAdapter for getting the sql statement</param>
        /// <param name="sql">The where clause</param>
        /// <param name="parameters">Parameters of the where clause</param>
        /// <param name="transaction">The transaction to run under, null (the default) if none</param>
        /// <param name="commandTimeout">Number of seconds before command execution timeout</param>
        /// <param name="fromCache">Cache the query.</param>
        /// <returns>True if records are deleted</returns>
        private static IEnumerable <T> GetList <T>(this IDbConnection connection, ISqlAdapter adapter, string sql, object parameters, IDbTransaction transaction = null, int?commandTimeout = null, bool fromCache = false) where T : class
        {
            var type      = typeof(T);
            var tinfo     = TableInfoCache(type);
            var selectSql = adapter.GetListQuery(tinfo, sql);

            return(connection.Query <T>(selectSql, parameters, transaction, commandTimeout: commandTimeout));

            //T obj;

            //if (type.IsInterface())
            //{
            //    var result = connection.Query(selectSql, parameters, transaction, commandTimeout: commandTimeout);

            //    if (result == null)
            //        return null;


            //    var list = new List<T>();
            //    foreach (IDictionary<string, object> res in result)
            //    {
            //        obj = ProxyGenerator.GetInterfaceProxy<T>();
            //        foreach (var property in tinfo.PropertyList)
            //        {
            //            var val = res[property.Name];
            //            if (val == null) continue;
            //            if (property.PropertyType.IsGenericType() && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
            //            {
            //                var genericType = Nullable.GetUnderlyingType(property.PropertyType);
            //                if (genericType != null) property.SetValue(obj, Convert.ChangeType(val, genericType), null);
            //            }
            //            else
            //            {
            //                property.SetValue(obj, Convert.ChangeType(val, property.PropertyType), null);
            //            }
            //        }

            //    ((IProxy)obj).IsDirty = false;   //reset change tracking and return
            //        list.Add(obj);
            //    }
            //    return list;
            //}
            //else
            //{
            //    return connection.Query<T>(selectSql, parameters, transaction, commandTimeout: commandTimeout);
            //}
        }