예제 #1
0
        protected internal IEnumerable <TBusinessEntity> ExecuteTableFunction <TBusinessEntity>(string tableFunction, params object[] parameters) where TBusinessEntity : class
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (var sqlcmd = conn.CreateCommand())
                {
                    InitSqlCommand(sqlcmd);
                    var sqlparams = new SqlParameter[parameters.Length];

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        sqlparams[i] = new SqlParameter("@p" + i, parameters[i]);
                    }

                    sqlcmd.CommandType = CommandType.Text;
                    sqlcmd.CommandText = "SELECT * FROM " + tableFunction + "(" +
                                         String.Join(",", sqlparams.Select(el => el.ParameterName)) + ")";
                    sqlcmd.Parameters.AddRange(sqlparams);

                    var reader = sqlcmd.ExecuteReader();

                    return(ReaderInjection.ReadAll <TBusinessEntity>(reader).ToArray());
                }
            }
        }
예제 #2
0
        public static IEnumerable <TBusinessEntity> ReadAll <TBusinessEntity>(IDataReader reader) where TBusinessEntity : class
        {
            var injecter = new ReaderInjection();

            while (reader.Read())
            {
                var obj = Activator.CreateInstance(typeof(TBusinessEntity)) as TBusinessEntity;
                injecter.Inject(reader, obj);
                yield return(obj);
            }
        }
예제 #3
0
        public IEnumerable <TBusinessEntity> ExecuteStoredProcedure <TBusinessEntity>(string storedProcedure, params SqlParameter[] parameters) where TBusinessEntity : class
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (var sqlcmd = conn.CreateCommand())
                {
                    InitSqlCommand(sqlcmd);
                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.CommandText = storedProcedure;

                    foreach (var parameter in parameters)
                    {
                        sqlcmd.Parameters.Add(parameter);
                    }

                    using (var reader = sqlcmd.ExecuteReader())
                    {
                        return(ReaderInjection.ReadAll <TBusinessEntity>(reader).ToArray());
                    }
                }
            }
        }
예제 #4
0
        protected internal IEnumerable <TBusinessEntity> ExecuteTableFunction <TBusinessEntity>(string tableFunction, params SqlParameter[] parameters) where TBusinessEntity : class
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (var sqlcmd = conn.CreateCommand())
                {
                    InitSqlCommand(sqlcmd);

                    sqlcmd.CommandType = CommandType.Text;
                    sqlcmd.CommandText = "SELECT * FROM " + tableFunction + "(" +
                                         String.Join(",", parameters.Select(el => el.ParameterName)) + ")";

                    foreach (var parameter in parameters)
                    {
                        sqlcmd.Parameters.Add(parameter);
                    }

                    var reader = sqlcmd.ExecuteReader();

                    return(ReaderInjection.ReadAll <TBusinessEntity>(reader).ToArray());
                }
            }
        }