Example #1
0
        public static PerformanceEntityCollection <T> PerformanceSelect <T>(string queryString, DataAccessParameterCollection parameters, CommandType cmdType)
            where T : EntityBase, new()
        {
            PerformanceEntityCollection <T> result = null;

            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                IDataReader reader = broker.ExecuteReader(queryString, parameters, cmdType);

                int           fieldCount = reader.FieldCount;
                List <string> columns    = new List <string>();
                object[]      values     = new object[fieldCount];
                for (int i = 0; i < fieldCount; i++)
                {
                    columns.Add(reader.GetName(i));
                }
                result = new PerformanceEntityCollection <T>(columns);

                while (reader.Read())
                {
                    reader.GetValues(values);
                    result.Add(values);
                }
                reader.Dispose();
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 获取数据通过Command
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">SQL</param>
        /// <returns></returns>
        public static EntityCollection <T> Select <T>(string queryString, DataAccessParameterCollection parameters, CommandType cmdType)
            where T : EntityBase, new()
        {
            EntityCollection <T> result = new EntityCollection <T>();

            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                IDataReader reader = broker.ExecuteReader(queryString, parameters, cmdType);

                int           fieldCount = reader.FieldCount;
                List <string> columns    = new List <string>();
                object[]      values     = new object[fieldCount];
                for (int i = 0; i < fieldCount; i++)
                {
                    columns.Add(reader.GetName(i));
                }

                while (reader.Read())
                {
                    T t = new T();
                    reader.GetValues(values);
                    for (int i = 0; i < fieldCount; i++)
                    {
                        if (!(values[i] == DBNull.Value))
                        {
                            t.SetData(columns[i], values[i]);
                            t.GetData(columns[i]);
                        }
                    }
                    result.Add(t);
                }
            }
            return(result);
        }
Example #3
0
        public static List <T> SelectSingleValue <T>(string queryString)
        {
            List <T> result = new List <T>();

            using (DataAccessBroker broker = DataAccessFactory.Instance(InstanceName))
            {
                IDataReader reader = broker.ExecuteReader(queryString, new DataAccessParameterCollection(), CommandType.Text);

                while (reader.Read())
                {
                    T tmp = (T)reader.GetValue(0);

                    result.Add(tmp);
                }
            }
            return(result);
        }
Example #4
0
        public static EntityCollection <T> SelectByBroker <T>(string queryString, DataAccessParameterCollection parameters, CommandType cmdType, DataAccessBroker broker)
            where T : EntityBase, new()
        {
            EntityCollection <T> result = new EntityCollection <T>();

            IDataReader reader = broker.ExecuteReader(queryString, parameters, cmdType);

            int           fieldCount = reader.FieldCount;
            List <string> columns    = new List <string>();

            Dictionary <string, Type>   columnType = new Dictionary <string, Type>();
            Dictionary <string, string> nameChange = new Dictionary <string, string>();

            T col = new T();

            object[] values = new object[fieldCount];
            for (int i = 0; i < fieldCount; i++)
            {
                columns.Add(reader.GetName(i));


                for (int m = 0; m < col.OringTableSchema.AllColumnInfo.Count; m++)
                {
                    if (col.OringTableSchema.AllColumnInfo[m].ColumnName.ToUpper() == reader.GetName(i).ToUpper())
                    {
                        columnType.Add(reader.GetName(i), col.OringTableSchema.AllColumnInfo[m].DataType);

                        nameChange.Add(reader.GetName(i), col.OringTableSchema.AllColumnInfo[m].ColumnName);
                    }
                }
            }

            while (reader.Read())
            {
                T t = new T();
                reader.GetValues(values);
                for (int i = 0; i < fieldCount; i++)
                {
                    if (!(values[i] == DBNull.Value))
                    {
                        if (!columnType.ContainsKey(columns[i]))
                        {
                            continue;
                        }

                        if (values[i].GetType() == columnType[columns[i]])
                        {
                            t.SetData(nameChange[columns[i]], values[i]);
                        }
                        else
                        {
                            if (columnType[columns[i]] == Type.GetType("System.Int32"))
                            {
                                t.SetData(nameChange[columns[i]], int.Parse(values[i].ToString()));
                            }
                            else if (columnType[columns[i]] == Type.GetType("System.Boolean"))
                            {
                                if (values[i].ToString() == "0")
                                {
                                    t.SetData(nameChange[columns[i]], false);
                                }
                                else
                                {
                                    t.SetData(nameChange[columns[i]], true);
                                }
                            }
                            else
                            {
                                t.SetData(nameChange[columns[i]], values[i]);
                            }
                        }
                    }
                }
                result.Add(t);
            }
            reader.Dispose();

            return(result);
        }