Example #1
0
        private string GetTableName(Type type)
        {
            string name = "";

            if (type.IsDefined(typeof(MyTableAttribute), false))
            {
                var attrs = type.GetCustomAttributes(false);
                foreach (var att in attrs)
                {
                    MyTableAttribute tableAttr = (MyTableAttribute)att;
                    if (tableAttr != null)
                    {
                        name = tableAttr.Name;
                    }
                }
            }
            else
            {
                name = type.Name;
            }
            return(name);
        }
Example #2
0
        /// <summary>
        /// 查询该表下所有数据
        /// </summary>
        /// <typeparam name="T">类型名</typeparam>
        /// <returns></returns>
        public virtual string SelectAllString <T>() where T : ModelBase
        {
            var    type = typeof(T);
            string name = "";

            if (type.IsDefined(typeof(MyTableAttribute), false))
            {
                var attrs = type.GetCustomAttributes(false);
                foreach (var att in attrs)
                {
                    MyTableAttribute tableAttr = (MyTableAttribute)att;
                    if (tableAttr != null)
                    {
                        name = tableAttr.Name;
                    }
                }
            }
            else
            {
                name = type.Name;
            }
            return("select * from " + name);
        }