示例#1
0
        public static List <T> GetResult <T>(MyCommand myCmd)
        {
            List <T>  rs        = new List <T>();
            DataTable dataTable = GetSqlAccess().ExecuteQuery(myCmd);
            Type      type      = typeof(T);
            TableInfo tableInfo = TableInfoHelper.GetTableInfo(type);

            foreach (DataRow row in dataTable.Rows)
            {
                T entity = System.Activator.CreateInstance <T>();
                foreach (TableFieldInfo fieldInfo in tableInfo.TableFieldInfoList)
                {
                    object value = DBNull.Value;
                    try
                    {
                        value = row[fieldInfo.Column];
                    }
                    // catch (ArgumentException e)
                    catch
                    {
                        // Debug.Log(e.ToString());
                        continue;
                    }

                    if (value.GetType().Equals(typeof(DBNull)))
                    {
                        continue;
                    }
                    // Debug.Log("注入:" + fieldInfo.Column + ":[" + value + "]");
                    type.GetProperty(fieldInfo.Property).SetValue(entity, value);
                }
                rs.Add(entity);
            }
            return(rs);
        }
示例#2
0
        public static int Count <T>()
        {
            TableInfo tableInfo = TableInfoHelper.GetTableInfo(typeof(T));
            string    sql       = string.Format(SqlCondition.COUNT, tableInfo.Key.Column, tableInfo.TableName);
            MyCommand myCommand = new MyCommand(sql, null);
            DataTable dataTable = GetSqlAccess().ExecuteQuery(myCommand);

            return(Convert.ToInt32(dataTable.Rows[0][0].ToString()));
        }