コード例 #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);
        }
コード例 #2
0
        //根据类型获取对应的对象配置信息。
        private ModelMappingInfo parseObjectMappingInfo(Type t)
        {
            ModelMappingInfo m = new ModelMappingInfo();

            m.ClassName  = t.Name;       //类名
            m.EntityType = t;            //实体类的类型
            parseModelMapping(t, m);     //实体类映射的表
            parseMetaData(t, m);
            return(m);
        }
コード例 #3
0
        //获取映射的表名。
        private ModelMappingInfo parseModelMapping(Type entityType, ModelMappingInfo m)
        {
            ModelMapAttribute tattr = Attribute.GetCustomAttribute(entityType, typeof(ModelMapAttribute)) as ModelMapAttribute;

            if (tattr != null)
            {
                m.MapTable          = tattr.TableName;
                m.XmlConfigFileName = tattr.XmlFileName;
                m.ConfigOptions     = tattr.ConfigOptions;
            }
            else
            {
                m.MapTable          = entityType.Name;
                m.XmlConfigFileName = entityType.Name;
                m.ConfigOptions     = MB.Orm.Enums.ModelConfigOptions.ColumnCfgByAttribute | MB.Orm.Enums.ModelConfigOptions.CreateSqlByXmlCfg;
            }
            return(m);
        }
コード例 #4
0
        //获取键值列。
        private Dictionary <string, FieldPropertyInfo> getKeyColumns(Type entityType, ModelMappingInfo m)
        {
            ModelMapAttribute tattr = Attribute.GetCustomAttribute(entityType, typeof(ModelMapAttribute)) as ModelMapAttribute;

            if (tattr == null)
            {
                throw new MB.Util.APPException(string.Format("在获取实体列时 类型{0} 没有配置 ModelMapAttribute 特性,请先配置", entityType.FullName));
            }

            string[] keys = tattr.PrimaryKeys;
            Dictionary <string, FieldPropertyInfo> pkeys = new Dictionary <string, FieldPropertyInfo>(keys.Length);

            for (int i = 0; i < keys.Length; i++)
            {
                string keyName = keys[i];
                if (m.FieldPropertys.ContainsKey(keyName))
                {
                    pkeys.Add(keyName, m.FieldPropertys[keyName]);
                }
                else
                {
                    throw new MB.Util.APPException(string.Format("指定的键值{0} 在实体类型{1}中不存在,或者存在但没有配置属性的MB.Orm.Mapping.Att.ColumnMap 特殊", keyName, entityType.FullName));
                }
                //MB.Util.TraceEx.Write(string.Format("指定的键值{0} 在实体类型{1}中不存在!",keyName,entityType.FullName), MB.Util.APPMessageType.SysErrInfo);
            }
            return(pkeys);
        }