internal static Type DetermineChildType(IQueryBuilder query, string propertyName) { string[] properties = propertyName.Split('.'); TypeSchema schema = SchemaCache.Current.GetSchema(query.QueriedType); for (int i = 0; i < properties.Length; i++) { if (i == properties.Length - 1) { ChildrenSchema childSchema = schema.FindChildrenSchema(properties[i]); if (childSchema == null) { throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, properties[i])); } return(childSchema.ChildType); } else { ParentSchema parentSchema = schema.FindParentSchema(properties[i]); if (parentSchema == null) { throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, properties[i])); } schema = SchemaCache.Current.GetSchema(parentSchema.Property.PropertyType); } } return(null); }
internal static string DetermineForeginKey(IQueryBuilder query, string propertyName) { string[] properties = propertyName.Split('.'); string table = String.Empty; string column = String.Empty; TypeSchema schema = SchemaCache.Current.GetSchema(query.QueriedType); for (int i = 0; i < properties.Length; i++) { if (i == properties.Length - 1) { ChildrenSchema childSchema = schema.FindChildrenSchema(properties[i]); if (childSchema == null) { throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, properties[i])); } TypeSchema childTypeSchema = SchemaCache.Current.GetSchema(childSchema.ChildType); ParentSchema parentSchema = childTypeSchema.FindParentSchema(childSchema.PropertyName); if (parentSchema == null) { throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, childSchema.PropertyName)); } column = String.Format(CultureInfo.CurrentCulture, query.Context.ColumnFormat, parentSchema.ColumnName); table = String.Format(CultureInfo.CurrentCulture, query.Context.TableFormat, childTypeSchema.TableName); } else { ParentSchema parentSchema = schema.FindParentSchema(properties[i]); if (parentSchema == null) { throw new ObjectServerException(String.Format(CultureInfo.CurrentCulture, "Could not locate schema for {0}.{1}", schema.Type.FullName, properties[i])); } schema = SchemaCache.Current.GetSchema(parentSchema.Property.PropertyType); } } return(String.Format(CultureInfo.CurrentCulture, query.Context.TableColumnFormat, table, column)); }
internal ServerObjectCollection SelectChildren(ServerObject obj, string propertyName) { Trace.WriteLineIf(DebugOutput.Enabled, "Selecting children for " + propertyName); TypeSchema schema = SchemaCache.Current.GetSchema(obj.ServerObjectType); ChildrenSchema childrenSchema = schema.FindChildrenSchema(propertyName); ServerObjectCollection children = null; object primaryKey = obj.Data.GetValue(schema.PrimaryKey.Property.Name); Query query = new Query(new Condition(childrenSchema.PropertyName, Expression.Equal, primaryKey)); children = Select(childrenSchema.ChildType, query); Trace.WriteLineIf(DebugOutput.Enabled, "Checking cache for more items"); foreach (ServerObject cacheItem in objectCache.GetCacheItem(childrenSchema.ChildType)) { if (primaryKey.Equals(cacheItem.Data.GetValue(childrenSchema.PropertyName)) && !children.Contains(cacheItem)) { children.Add(cacheItem); } } ServerObjectCollection toRemove = new ServerObjectCollection(); foreach (ServerObject child in children) { if (!primaryKey.Equals(child.Data.GetValue(childrenSchema.PropertyName))) { toRemove.Add(child); } } foreach (ServerObject child in toRemove) { children.Remove(child); } return(children); }