示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// 判断该类型是否存在实体映射的配置信息。
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool CheckExistsModelMapping(Type t)
        {
            ModelMapAttribute tattr = Attribute.GetCustomAttribute(t, typeof(ModelMapAttribute)) as ModelMapAttribute;

            return(tattr != null);
        }