private void InitialRelationField() { if (!ObjectType.IsSubclassOf(typeof(DataEntity))) { return; } PropertyInfo[] propertys = ObjectType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo pi in propertys) { //关联属性 //RelationAttribute[] relationAttributes = AttributeCore.GetPropertyAttributes<RelationAttribute>(pi, true); //IRelationConfig[] configs = ConfigManager.LoadRelationConfigs(pi); IRelationFieldConfig config = ConfigManager.LoadRelationFieldConfig(pi); if (config != null && config.RelationKeyCount > 0) { RelationFieldMapping mapping = new RelationFieldMapping(this, pi.PropertyType, pi.Name); foreach (RelationKey key in config.GetRelationKeys()) { mapping.AddRelationKeys(key.MasterKey, key.RelateKey); } if (!string.IsNullOrEmpty(config.PropertyName)) { //设定关联属性名称,使用时才生成对应关系 mapping.SetRelationProperty(config.PropertyName); } _relationMappingDictionary.Add(mapping.RelationName, mapping); } } }
//internal static IRelationConfig[] LoadRelationConfigs(PropertyInfo pi) //{ // IRelationConfig[] configs = null; // RelationAttribute[] attributes = AttributeCore.GetPropertyAttributes<RelationAttribute>(pi, true); // if (attributes.Length > 0) // { // configs = attributes; // } // return configs; //} //internal static IRelationPropertyConfig LoadRelationPropertyConfig(PropertyInfo pi) //{ // IRelationPropertyConfig config = null; // RelationPropertyAttribute[] attributes = AttributeCore.GetPropertyAttributes<RelationPropertyAttribute>(pi, true); // if (attributes.Length > 0) // { // config = attributes[0]; // } // return config; //} internal static IRelationFieldConfig LoadRelationFieldConfig(PropertyInfo pi) { IRelationFieldConfig config = null; if (config == null) { LightDataConfig lightDataConfig = GetConfig(); if (lightDataConfig != null && lightDataConfig.ContainDataTableConfig(pi.ReflectedType)) { DataTableConfig dtconfig = lightDataConfig.GetDataTableConfig(pi.ReflectedType); IConfiguratorFieldConfig fieldConfig = dtconfig[pi.Name]; if (fieldConfig != null) { if (fieldConfig is IgnoraFieldConfig) { return(null); } config = dtconfig[pi.Name] as RelationFieldConfig; } } } if (config == null) { RelationAttribute[] relationAttributes = AttributeCore.GetPropertyAttributes <RelationAttribute>(pi, true); if (relationAttributes.Length > 0) { RelationFieldConfig rfConfig = new RelationFieldConfig(pi.Name); foreach (RelationAttribute ra in relationAttributes) { rfConfig.AddRelationKeys(ra.MasterKey, ra.RelateKey); } RelationPropertyAttribute[] relationPropertyAttributes = AttributeCore.GetPropertyAttributes <RelationPropertyAttribute>(pi, true); if (relationPropertyAttributes.Length > 0) { rfConfig.PropertyName = relationPropertyAttributes[0].PropertyName; } config = rfConfig; } } return(config); }