/// <summary> /// Sets all property as modified. /// </summary> public void SetAllPropertiesAsModified() { string[] columnNames = GetPropertyMappingColumnNames(); object[] columnValues = GetPropertyValues(); PropertyConfiguration[] pcs = MetaDataManager.GetEntityConfiguration(_entityType.FullName).Properties; lock (changedProperties) { changedProperties.Clear(); int j = 0; for (int i = 0; i < columnNames.Length; i++) { while (pcs[j].MappingName != columnNames[i]) { j++; } if (!pcs[j].IsPrimaryKey) { changedProperties.Add(pcs[j].Name, columnValues[i]); } } } }
/// <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(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> /// 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> /// Convert an entity array to a data table. /// </summary> /// <param name="objs">The entity array.</param> /// <returns>The data table.</returns> public static DataTable EntityArrayToDataTable(DynEntityType entityType, DynEntity[] objs) { EntityConfiguration ec; if (objs != null && objs.Length > 0) { ec = MetaDataManager.GetEntityConfiguration(objs[0].EntityType.FullName); } else { ec = MetaDataManager.GetEntityConfiguration(entityType.FullName); } DataTable table = new DataTable(ec.Name); foreach (PropertyConfiguration pc in ec.Properties) { if ((!pc.IsQueryProperty) || (pc.QueryType == "FkReverseQuery")) { DataColumn column = new DataColumn(pc.QueryType == "FkReverseQuery" ? pc.MappingName : pc.Name, Util.GetType(pc.PropertyMappingColumnType.Replace("System.Nullable`1[", "").Replace("]", ""))); table.Columns.Add(column); } } if (objs != null && objs.Length > 0) { for (int i = 0; i < objs.Length; i++) { object[] values = DynEntity.GetPropertyValues(objs[i], DynEntity.GetPropertyMappingColumnNames(MetaDataManager.GetEntityConfiguration(objs[0].EntityType.Name))); DataRow row = table.NewRow(); int j = 0; foreach (PropertyConfiguration pc in ec.Properties) { if ((!pc.IsQueryProperty) || (pc.QueryType == "FkReverseQuery")) { object value = (values[j] == null ? DBNull.Value : values[j]); //if (pc.IsCompoundUnit) //{ // value = SerializationManager.Serialize(value); //} row[j] = value; } j++; } table.Rows.Add(row); } } table.AcceptChanges(); return(table); }
/// <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> /// Reloads all queries properties's value. /// </summary> /// <param name="includeLazyLoadQueries">if set to <c>true</c> [include lazy load queries].</param> public void ReloadQueries(bool includeLazyLoadQueries) { foreach (DynPropertyConfiguration item in _entityType.GetProperties()) { if (item.IsQueryProperty) { if (includeLazyLoadQueries || (!MetaDataManager.IsLazyLoad(_entityType.FullName, item.Name))) { _queryPropertyValues[_queryPropertyNameIdMap["_" + item.Name]] = QueryOne(new DynEntity(item.Name), item.Name, this); // _queryPropertyValues[_queryPropertyNameIdMap["_" + item.Name]] = QueryOne(new DynEntity(item.PropertyOriginalEntityType), item.Name, this); } } } }
/// <summary> /// flush Entities in EntityTypeManager into MetaDataManager /// </summary> public static void EntityTypes2EntityConfiguration() { List <EntityConfiguration> ecs = new List <EntityConfiguration>(); foreach (DynEntityType et in DynEntityTypeManager.Entities) { if (!MetaDataManager.isExistEntityConfiguration(et.Name)) { ecs.Add(EntityType2EntityConfiguration(et)); } } MetaDataManager.AddEntityConfigurations(ecs.ToArray()); }
/// <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); } } }
private static void LoadEmbeddedEntityConfigurationsFromLoadedEntities() { List <EntityConfiguration> list = new List <EntityConfiguration>(); try { System.Reflection.Assembly[] asses = AppDomain.CurrentDomain.GetAssemblies(); for (int i = asses.Length - 1; i >= 0; i--) { System.Reflection.Assembly ass = asses[i]; try { foreach (Type t in ass.GetTypes()) { if (t.IsSubclassOf(typeof(Entity)) && t != typeof(Entity) && (!t.IsAbstract)) { EntityConfiguration item = GetEmbeddedEntityConfigurationsFromEntityType(t); if (item != null) { list.Add(item); } } } } catch { } } } catch { } if (list.Count > 0) { MetaDataManager.AddEntityConfigurations(list.ToArray()); } }
/// <summary> /// Gets the primary DEFAULT_KEY values. /// </summary> /// <param name="type">The type.</param> /// <param name="obj">The obj.</param> /// <returns>The values.</returns> public static object[] GetPrimaryKeyValues(DynEntity obj) { Check.Require(obj != null, "obj could not be null."); return(GetPropertyValues(obj, GetPrimaryKeyMappingColumnNames(MetaDataManager.GetEntityConfiguration(((DynEntity)obj).EntityType.FullName)))); }
/// <summary> /// Gets the create property mapping column names. /// </summary> /// <returns>Column names</returns> public string[] GetPropertyMappingColumnNames() { return(GetPropertyMappingColumnNames(MetaDataManager.GetEntityConfiguration(_entityType.FullName))); }
public static DbType[] GetCreatePropertyMappingColumnTypes(DynEntityType entityType) { return(GetCreatePropertyMappingColumnTypes(MetaDataManager.GetEntityConfiguration(entityType.FullName))); }
public static DbType[] GetCreatePropertyMappingColumnTypes(Type type) { return(GetCreatePropertyMappingColumnTypes(MetaDataManager.GetEntityConfiguration(type.ToString()))); }