Esempio n. 1
0
        //获取配置的列信息。
        private ModelMappingInfo parseMetaData(Type t, ModelMappingInfo m)
        {
            #region 字段信息
            PropertyInfo[] pinfos = t.GetProperties();                              //所有的属性
            m.FieldPropertys = new Dictionary <string, FieldPropertyInfo>(pinfos.Length);

            foreach (PropertyInfo pinfo in pinfos)
            {
                ExclusiveAttribute eattr = Attribute.GetCustomAttribute(pinfo, typeof(ExclusiveAttribute)) as ExclusiveAttribute;
                if (!Object.Equals(eattr, null))
                {
                    continue;
                }
                ColumnMapAttribute cattr = Attribute.GetCustomAttribute(pinfo, typeof(ColumnMapAttribute)) as ColumnMapAttribute;
                if (cattr == null)
                {
                    continue;
                }

                FieldPropertyInfo fd = new FieldPropertyInfo();
                fd.PropertyInfo  = pinfo;
                fd.PropertyName  = pinfo.Name;
                fd.DeclaringType = pinfo.DeclaringType;


                fd.FieldName    = cattr.ColumnName;
                fd.DbType       = cattr.DbType;
                fd.DefaultValue = cattr.DefaultValue;
                //}
                //else {
                //    fd.FieldName = fd.PropertyName;
                //    fd.DbType = DbType.Object;
                //    fd.DefaultValue = String.Empty;
                //}

                AutoIncreaseAttribute aattr = Attribute.GetCustomAttribute(pinfo, typeof(AutoIncreaseAttribute)) as AutoIncreaseAttribute;
                if (!Object.Equals(null, aattr))
                {
                    fd.AutoIncrease        = m.HasAutoIncreasePorperty = true;
                    fd.Step                = aattr.Step;
                    m.AutoIncreasePorperty = fd.PropertyName;
                }
                m.FieldPropertys.Add(fd.PropertyName, fd);
            }

            m.PrimaryKeys = getKeyColumns(t, m);
            if (m.PrimaryKeys.Count > 1)
            {
                m.IsMultiPrimaryKey = true;
            }
            else
            {
                m.IsMultiPrimaryKey = false;
            }

            #endregion
            return(m);
        }
Esempio n. 2
0
        //获取实体对象的所有列
        private List <string> getDbColumns(Type entityType)
        {
            PropertyInfo[] pinfos  = entityType.GetProperties();
            List <string>  columns = new List <string>();

            foreach (PropertyInfo pinfo in pinfos)
            {
                ColumnMapAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(ColumnMapAttribute)) as ColumnMapAttribute;
                if (attr == null)
                {
                    continue;
                }
                columns.Add(attr.ColumnName);
            }
            return(columns);
        }