/// <summary> /// Get the property value. /// </summary> /// <param name="propertyName"></param> /// <returns>The value.</returns> public object GetPropertyValue(string propertyName) { string entityPropertyName = propertyName; bool isFKProperty = false; string newpropertyName = null; if (_fkPropertyNameNormalPropertyNameMap.TryGetValue("_" + propertyName, out newpropertyName)) { entityPropertyName = newpropertyName; isFKProperty = true; } DynPropertyConfiguration entityProperty = GetEntityProperty(entityPropertyName); if (entityProperty.IsQueryProperty == true && isFKProperty == false) { if (entityProperty.IsArray) { if (!IsQueryPropertyLoaded(propertyName)) { DynEntityArrayList _al = new DynEntityArrayList(); _al.AddRange(Query(new DynEntity(entityProperty.PropertyOriginalEntityType), propertyName, this)); OnQueryPropertyChanged(propertyName, _queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]], _al); _queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] = _al; } if (_queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] == null) { DynEntityArrayList _al = new DynEntityArrayList(); BindArrayListEventHandlers(propertyName, _al); _queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] = _al; } return(_queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]]); } else { if (!IsQueryPropertyLoaded(propertyName)) { _queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] = QueryOne(new DynEntity(entityProperty.PropertyOriginalEntityType), propertyName, this); } return(_queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]]); } } else { if (_normalPropertyNameIdMap.ContainsKey("_" + propertyName)) { return(_normalPropertyValues[_normalPropertyNameIdMap["_" + propertyName]]); } else { return(null); } } }
public static PropertyItem P(string typeName, string propertyName) { DynEntityType entityType = DynEntityTypeManager.GetEntityTypeMandatory(typeName); DynPropertyConfiguration property = entityType.GetProperty(propertyName); if (property.IsInherited) { DynEntityType baseEntityType = DynEntityTypeManager.GetEntityTypeMandatory(property.InheritEntityMappingName); return(new PropertyItem(propertyName, baseEntityType.FullName)); } else { return(new PropertyItem(propertyName, entityType.FullName)); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="propertyName">属性名</param> public DynPropertyConfiguration(DynPropertyConfiguration orientProperty) { _name = orientProperty._name; _propertyType = orientProperty._propertyType; _isArray = orientProperty._isArray; _isInherited = orientProperty._isInherited; _inheritEntityMappingName = orientProperty._inheritEntityMappingName; _entityType = orientProperty._entityType; _propertyOriginalEntityType = orientProperty._propertyOriginalEntityType; _relatedType = orientProperty._relatedType; _propertyType = orientProperty.PropertyType; _isInherited = orientProperty.IsInherited; _isQueryProperty = orientProperty.IsQueryProperty; _isReadOnly = orientProperty.IsReadOnly; _inheritEntityMappingName = orientProperty.InheritEntityMappingName; //_isCompoundUnit = orientProperty.IsCompoundUnit; _comment = orientProperty.Comment; _customData = orientProperty.CustomData; _isContained = orientProperty.IsContained; _isFriendKey = orientProperty.IsFriendKey; _isIndexProperty = orientProperty.IsIndexProperty; _isIndexPropertyDesc = orientProperty.IsIndexPropertyDesc; _isInherited = orientProperty.IsInherited; _isLazyLoad = orientProperty.IsLazyLoad; _isNotNull = orientProperty.IsNotNull; _isPrimaryKey = orientProperty.IsPrimaryKey; _isQueryProperty = orientProperty.IsQueryProperty; _isReadOnly = orientProperty.IsReadOnly; _isRelationKey = orientProperty.IsRelationKey; _isSerializationIgnore = orientProperty.IsSerializationIgnore; _mappingName = orientProperty.MappingName; _name = orientProperty.Name; _propertyMappingColumnType = orientProperty.PropertyMappingColumnType; _propertyType = orientProperty.PropertyType; _queryOrderBy = orientProperty.QueryOrderBy; _queryType = orientProperty.QueryType; _queryWhere = orientProperty.QueryWhere; _relatedForeignKey = orientProperty.RelatedForeignKey; _relatedType = orientProperty.RelatedType; _relationType = orientProperty.RelationType; _sqlDefaultValue = orientProperty.SqlDefaultValue; _sqlType = orientProperty.SqlType; _attributes.AddRange(orientProperty.Attributes); }
public DynPropertyConfiguration GetProperty(string propertyName) { if (_properties.Contains(propertyName)) { return(_properties[propertyName]); } else { if (!string.IsNullOrEmpty(_baseEntityName) && BaseEntityType != null) { DynPropertyConfiguration inheritedProperty = BaseEntityType.GetProperty(propertyName); inheritedProperty.IsInherited = true; if (inheritedProperty.InheritEntityMappingName == null) { inheritedProperty.InheritEntityMappingName = BaseEntityType.Name; } return(inheritedProperty); } throw new ApplicationException("当前类或基类没有名称为" + propertyName + "的属性!"); } }
/// <summary> /// Set the property value /// </summary> /// <param name="propertyName"></param> /// <param name="propertyValue"></param> public void SetProportyValue(string propertyName, object propertyValue) { string entityPropertyName = propertyName; bool isFKProperty = false; string normalPropertyName = null; if (_fkPropertyNameNormalPropertyNameMap.TryGetValue("_" + propertyName, out normalPropertyName)) { entityPropertyName = normalPropertyName; isFKProperty = true; } DynPropertyConfiguration entityProperty = GetEntityProperty(entityPropertyName); if (entityProperty.IsQueryProperty == true && isFKProperty == false) { if (entityProperty.IsArray) { OnPropertyChanged(propertyName, _queryPropertyValues[_queryPropertyNameIdMap[propertyName]], propertyValue); int index = 0; if (_queryPropertyNameIdMap.TryGetValue("_" + propertyName, out index)) { _queryPropertyValues[index] = propertyValue; } } else { QueryDynAttribute qa = entityProperty.GetPropertyQueryAttribute(); DynQueryDescriber describer = new DynQueryDescriber(qa, entityProperty, entityProperty.PropertyOriginalEntityType, _entityType.Name); OnQueryOnePropertyChanged(propertyName, GetPropertyValue(propertyName), propertyValue); _queryPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] = propertyValue; if (propertyValue == null) { //OnPropertyChanged(propertyName, _normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName + "_" + describer.RelatedForeignKey]], null); //_normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName + "_" + describer.RelatedForeignKey]] = null; OnPropertyChanged(propertyName, _normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName]], null); _normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] = null; } else { //OnPropertyChanged(propertyName, _normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName + "_" + describer.RelatedForeignKey]], (propertyValue as DynEntity).GetPropertyValue(describer.RelatedForeignKey)); //_normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName + "_" + describer.RelatedForeignKey]] = (propertyValue as DynEntity).GetPropertyValue(describer.RelatedForeignKey); OnPropertyChanged(propertyName, _normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName]], (propertyValue as DynEntity).GetPropertyValue(describer.RelatedForeignKey)); _normalPropertyValues[_queryPropertyNameIdMap["_" + propertyName]] = (propertyValue as DynEntity).GetPropertyValue(describer.RelatedForeignKey); } } } else { OnPropertyChanged(propertyName, GetPropertyValue(propertyName), propertyValue); int index = 0; if (_normalPropertyNameIdMap.TryGetValue("_" + propertyName, out index)) { _normalPropertyValues[index] = propertyValue; } } }
public void AddProperty(DynPropertyConfiguration dynProperty) { _properties.Add(dynProperty); }
/// <summary> /// new an EntityType from an EntityConfiguration /// </summary> /// <param name="ec"></param> /// <returns></returns> public static DynEntityType EntityConfiguration2EntityType(EntityConfiguration ec) { string nameSpace, typeName, baseName; Util.SplitFullName(ec.Name, out nameSpace, out typeName); DynEntityType et; if (string.IsNullOrEmpty(ec.BaseEntity)) { et = new DynEntityType(typeName); } else { Util.SplitFullName(ec.BaseEntity, out nameSpace, out baseName); et = new DynEntityType(typeName, baseName); } et.AdditionalSqlScript = ec.AdditionalSqlScript; et.BaseEntityName = ec.BaseEntity; et.BatchSize = ec.BatchSize; et.Comment = ec.Comment; et.CustomData = ec.CustomData; et.IsAutoPreLoad = ec.IsAutoPreLoad; et.IsBatchUpdate = ec.IsBatchUpdate; et.IsReadOnly = ec.IsReadOnly; et.IsRelation = ec.IsRelation; et.MappingName = ec.MappingName; et.Namespace = nameSpace; et.Name = typeName; et.ViewName = ec.ViewName; if (string.IsNullOrEmpty(nameSpace) == false) { et.Attributes.Add(new OutputNamespaceDynAttribute(nameSpace)); } if (string.IsNullOrEmpty(ec.MappingName) == false | string.IsNullOrEmpty(ec.ViewName) == false) { et.Attributes.Add(new MappingNameDynAttribute(ec.MappingName)); } if (string.IsNullOrEmpty(ec.Comment) == false) { et.Attributes.Add(new CommentDynAttribute(ec.Comment)); } if (string.IsNullOrEmpty(ec.CustomData) == false) { et.Attributes.Add(new CustomDataDynAttribute(ec.CustomData)); } if (string.IsNullOrEmpty(ec.AdditionalSqlScript) == false) { et.Attributes.Add(new AdditionalSqlScriptDynAttribute(ec.AdditionalSqlScript)); } if (ec.IsReadOnly) { et.Attributes.Add(new ReadOnlyDynAttribute()); } if (ec.IsAutoPreLoad) { et.Attributes.Add(new AutoPreLoadDynAttribute()); } if (ec.IsBatchUpdate) { et.Attributes.Add(new BatchUpdateDynAttribute(ec.BatchSize)); } if (ec.IsRelation) { et.Attributes.Add(new RelationDynAttribute()); } foreach (PropertyConfiguration pc in ec.Properties) { if (pc.IsInherited) { continue; } DynPropertyConfiguration property = new DynPropertyConfiguration(pc.Name); property.PropertyType = pc.PropertyType; property.IsInherited = pc.IsInherited; property.IsQueryProperty = pc.IsQueryProperty; property.IsReadOnly = pc.IsReadOnly; property.InheritEntityMappingName = pc.InheritEntityMappingName; //property.IsCompoundUnit = pc.IsCompoundUnit; property.Comment = pc.Comment; property.CustomData = pc.CustomData; property.IsContained = pc.IsContained; property.IsFriendKey = pc.IsFriendKey; property.IsIndexProperty = pc.IsIndexProperty; property.IsIndexPropertyDesc = pc.IsIndexPropertyDesc; property.IsInherited = pc.IsInherited; property.IsLazyLoad = pc.IsLazyLoad; property.IsNotNull = pc.IsNotNull; property.IsPrimaryKey = pc.IsPrimaryKey; property.IsQueryProperty = pc.IsQueryProperty; property.IsReadOnly = pc.IsReadOnly; property.IsRelationKey = pc.IsRelationKey; property.IsSerializationIgnore = pc.IsSerializationIgnore; property.MappingName = pc.MappingName; property.Name = pc.Name; property.PropertyMappingColumnType = pc.PropertyMappingColumnType; property.PropertyType = pc.PropertyType; property.QueryOrderBy = pc.QueryOrderBy; property.QueryType = pc.QueryType; property.QueryWhere = pc.QueryWhere; property.RelatedForeignKey = pc.RelatedForeignKey; property.RelatedType = pc.RelatedType; property.RelationType = pc.RelationType; property.SqlDefaultValue = pc.SqlDefaultValue; property.SqlType = pc.SqlType; if (pc.IsFriendKey) { property.Attributes.Add(new FriendKeyDynAttribute(pc.RelatedType)); } if (string.IsNullOrEmpty(pc.SqlType) == false) { property.Attributes.Add(new SqlTypeDynAttribute(pc.SqlType)); } if (pc.IsReadOnly) { property.Attributes.Add(new ReadOnlyDynAttribute()); } //if (pc.IsCompoundUnit) // property.Attributes.Add(new CompoundUnitDynAttribute()); if (pc.IsPrimaryKey) { property.Attributes.Add(new PrimaryKeyDynAttribute()); } if (pc.IsRelationKey) { property.Attributes.Add(new RelationKeyDynAttribute(pc.RelatedForeignKey)); } if (pc.IsIndexPropertyDesc) { property.Attributes.Add(new PrimaryKeyDynAttribute()); } if (pc.IsNotNull) { property.Attributes.Add(new NotNullDynAttribute()); } if (pc.IsSerializationIgnore) { property.Attributes.Add(new SerializationIgnoreDynAttribute()); } if (string.IsNullOrEmpty(pc.MappingName) == false) { property.Attributes.Add(new MappingNameDynAttribute(pc.MappingName)); } if (string.IsNullOrEmpty(pc.Comment) == false) { property.Attributes.Add(new CommentDynAttribute(pc.Comment)); } if (string.IsNullOrEmpty(pc.CustomData) == false) { property.Attributes.Add(new CustomDataDynAttribute(pc.CustomData)); } if (pc.IsQueryProperty) { QueryType queryType = (QueryType)Enum.Parse(typeof(QueryType), pc.QueryType); switch (queryType) { case QueryType.CustomQuery: CustomQueryDynAttribute customQueryDynAttribute = new CustomQueryDynAttribute(pc.QueryWhere); customQueryDynAttribute.OrderBy = pc.QueryOrderBy; customQueryDynAttribute.RelationType = pc.RelationType; customQueryDynAttribute.LazyLoad = pc.IsLazyLoad; property.Attributes.Add(customQueryDynAttribute); break; case QueryType.FkQuery: FkQueryDynAttribute fkQueryDynAttribute = new FkQueryDynAttribute(pc.RelatedForeignKey); //zml ??? fkQueryDynAttribute.AdditionalWhere = pc.QueryWhere; fkQueryDynAttribute.LazyLoad = pc.IsLazyLoad; fkQueryDynAttribute.OrderBy = pc.QueryOrderBy; property.Attributes.Add(fkQueryDynAttribute); property.IsArray = true; break; case QueryType.FkReverseQuery: FkReverseQueryDynAttribute fkReverseQueryDynAttribute = new FkReverseQueryDynAttribute(true); fkReverseQueryDynAttribute.LazyLoad = pc.IsLazyLoad; property.Attributes.Add(fkReverseQueryDynAttribute); break; case QueryType.ManyToManyQuery: ManyToManyQueryDynAttribute manyToManyQueryDynAttribute = new ManyToManyQueryDynAttribute(pc.RelationType); manyToManyQueryDynAttribute.AdditionalWhere = pc.QueryWhere; manyToManyQueryDynAttribute.LazyLoad = pc.IsLazyLoad; manyToManyQueryDynAttribute.OrderBy = pc.QueryOrderBy; property.Attributes.Add(manyToManyQueryDynAttribute); property.IsArray = true; break; case QueryType.PkQuery: PkQueryDynAttribute pkQueryDynAttribute = new PkQueryDynAttribute(); pkQueryDynAttribute.LazyLoad = pc.IsLazyLoad; property.Attributes.Add(pkQueryDynAttribute); break; case QueryType.PkReverseQuery: PkReverseQueryDynAttribute pkReverseQueryDynAttribute = new PkReverseQueryDynAttribute(true); pkReverseQueryDynAttribute.LazyLoad = pc.IsLazyLoad; property.Attributes.Add(pkReverseQueryDynAttribute); break; } } if (pc.IsIndexProperty) { IndexPropertyDynAttribute indexPropertyDynAttribute = new IndexPropertyDynAttribute(pc.IsIndexPropertyDesc); property.Attributes.Add(indexPropertyDynAttribute); } if (property.IsQueryProperty) { if (property.IsArray) { property.PropertyOriginalEntityType = property.PropertyType.Replace(nameSpace + ".", "").Replace("ArrayList", ""); } else { property.PropertyOriginalEntityType = property.PropertyType.Replace(nameSpace + ".", ""); } } else { property.PropertyOriginalEntityType = property.PropertyType; } et.AddProperty(property); } return(et); }