/// <summary> /// Gets the modified properties of this entity, not including query properties and properties of base entity's. /// </summary> /// <param name="type">The type.</param> /// <returns>The modified properties</returns> public Dictionary <string, object> GetModifiedProperties(DynEntityType entityType) { EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(entityType.FullName); if (string.IsNullOrEmpty(entityType.BaseEntityName)) { return(changedProperties); } List <string> toRemoveItems = new List <string>(); foreach (string item in changedProperties.Keys) { PropertyConfiguration pc = ec.GetPropertyConfiguration(item); if (pc == null || pc.IsInherited || pc.IsPrimaryKey) { toRemoveItems.Add(item); } } Dictionary <string, object> retProperties = new Dictionary <string, object>(); foreach (string item in changedProperties.Keys) { if (!toRemoveItems.Contains(item)) { retProperties.Add(item, changedProperties[item]); } } return(retProperties); }
/// <summary> /// Called when query one property changed. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected void OnQueryOnePropertyChanged(string propertyName, object oldValue, object newValue) { bool isLoadedBefore = IsQueryPropertyLoaded(propertyName); SetPropertyLoaded(propertyName); if (!isLoadedBefore) { return; } if (oldValue == newValue) { return; } EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(EntityType.FullName); PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName); if ((!(pc.IsContained || pc.QueryType == "ManyToManyQuery"))) { return; } if (oldValue != null) { OnQueryPropertyItemRemove(propertyName, oldValue); } if (newValue != null) { OnQueryPropertyItemAdd(propertyName, newValue); } }
/// <summary> /// Gets the modified properties of this entity, not including query properties and properties of base entity's. /// </summary> /// <param name="type">The type.</param> /// <returns>The modified properties</returns> public Dictionary <string, object> GetModifiedProperties(Type type) { EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(type.ToString()); if (ec.BaseEntity == null && type == this.GetType()) { return(changedProperties); } Check.Require(typeof(Entity).IsAssignableFrom(type), "type must be an Entity"); List <string> toRemoveItems = new List <string>(); foreach (string item in changedProperties.Keys) { PropertyConfiguration pc = ec.GetPropertyConfiguration(item); if (pc == null || pc.IsInherited || pc.IsPrimaryKey) { toRemoveItems.Add(item); } } Dictionary <string, object> retProperties = new Dictionary <string, object>(); foreach (string item in changedProperties.Keys) { if (!toRemoveItems.Contains(item)) { retProperties.Add(item, changedProperties[item]); } } return(retProperties); }
/// <summary> /// Queries array of the specified return entity type. /// </summary> /// <param name="returnEntityType">Type of the return entity.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="baseEntity">The base entity.²»ÊÇ»ùÀà</param> /// <returns>The query result.</returns> protected object Query(Type returnEntityType, string propertyName, Entity baseEntity) { if (onQuery != null) { EntityConfiguration ec = baseEntity.GetEntityConfiguration(); PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName); return(onQuery(returnEntityType, propertyName, pc.QueryWhere, pc.QueryOrderBy, baseEntity)); } return(null); }
/// <summary> /// Called when removed item from query property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="item">The item.</param> protected void OnQueryPropertyItemRemove(string propertyName, object item) { Check.Require(item != null, "item to remove could not be null."); bool isLoadedBefore = IsQueryPropertyLoaded(propertyName); SetPropertyLoaded(propertyName); if (!isLoadedBefore) { return; } EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(EntityType.FullName); PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName); if ((!(pc.IsContained || pc.QueryType == "ManyToManyQuery"))) { return; } bool isInSaveList = false; lock (toSaveRelatedPropertyObjects) { List <object> values = null; if (toSaveRelatedPropertyObjects.TryGetValue(propertyName, out values) && toSaveRelatedPropertyObjects[propertyName].Contains(item)) { values.Remove(item); isInSaveList = true; } } if (!isInSaveList) { lock (toDeleteRelatedPropertyObjects) { List <object> values = null; if (!toDeleteRelatedPropertyObjects.TryGetValue(propertyName, out values)) { values = new List <object>(); toDeleteRelatedPropertyObjects.Add(propertyName, values); } if (!values.Contains(item)) { values.Add(item); } } } }
/// <summary> /// Queries array of the specified return entity type. /// </summary> /// <param name="returnEntityType">Type of the return entity.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="baseEntity">The base entity.</param> /// <returns>The query result.</returns> protected DynEntity[] Query(DynEntity returnEntityType, string propertyName, DynEntity baseEntity) { if (onQuery != null) { EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(baseEntity.EntityType.FullName); PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName); try { return(onQuery(returnEntityType, propertyName, pc.QueryWhere, pc.QueryOrderBy, baseEntity)); } catch (Exception ex) { onQuery = null; throw ex; } } return(null); }
/// <summary> /// Called when query property changed. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="oldValues">The old values.</param> /// <param name="newValues">The new values.</param> protected void OnQueryPropertyChanged(string propertyName, object oldValues, object newValues) { bool isLoadedBefore = IsQueryPropertyLoaded(propertyName); SetPropertyLoaded(propertyName); if (newValues != null) { BindArrayListEventHandlers(propertyName, newValues); } if (!isLoadedBefore) { return; } EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(EntityType.FullName); PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName); if ((!(pc.IsContained || pc.QueryType == "ManyToManyQuery")) || oldValues == newValues) { return; } if (oldValues != null) { foreach (object oldValue in (IEnumerable)oldValues) { OnQueryPropertyItemRemove(propertyName, oldValue); } } if (newValues != null) { foreach (object newValue in (IEnumerable)newValues) { OnQueryPropertyItemAdd(propertyName, newValue); } } }