private void UpdateTypeAncestor(StoredTypeInfo type) { if (string.IsNullOrEmpty(type.AncestorName)) { return; } type.Ancestor = types[type.AncestorName]; }
private void UpdateFieldDeclaringType(StoredFieldInfo field, StoredTypeInfo type) { field.DeclaringType = type; foreach (var nestedField in field.Fields) { UpdateFieldDeclaringType(nestedField, type); } }
private void UpdateTypeAllFields(StoredTypeInfo type) { var fields = new List <StoredFieldInfo>(); var currentType = type; while (currentType != null) { fields.AddRange(currentType.Fields); currentType = currentType.Ancestor; } type.AllFields = fields.ToArray(); }
private void UpdateTypeAllAncestors(StoredTypeInfo type) { var result = new List <StoredTypeInfo>(); var currentAncestor = type.Ancestor; while (currentAncestor != null) { result.Add(currentAncestor); currentAncestor = currentAncestor.Ancestor; } result.Reverse(); type.AllAncestors = result.ToArray(); }
private void UpdateTypeHierarchy(StoredTypeInfo type) { var currentType = type; while (currentType != null && !currentType.IsHierarchyRoot) { currentType = currentType.Ancestor; } if (currentType != null && currentType.IsHierarchyRoot) { type.Hierarchy = hierarchies[currentType]; } }
private StoredTypeInfo ConvertType(TypeInfo source) { var inheritedAssociatedFields = new HashSet <string>(); var declaredFields = source.Fields .Where(field => field.IsDeclared && !field.IsNested) .ToArray(); var sourceAncestor = source.GetAncestor(); string hierarchyRoot = null; if (source.Hierarchy != null && source.Hierarchy.Root == source) { hierarchyRoot = source.Hierarchy.InheritanceSchema.ToString(); } var associations = source.GetOwnerAssociations() .Where(a => { if (processedAssociations.Contains(a.Name)) { return(false); } if (declaredFields.Contains(a.OwnerField)) { return(true); } if (a.IsPaired) { inheritedAssociatedFields.Add(a.OwnerField.Name); return(true); } return(false); }) .Select(ConvertAssociation) .ToArray(); foreach (var association in associations) { processedAssociations.Add(association.Name); } var fields = source.Fields .Where(field => (field.IsDeclared && !field.IsNested) || inheritedAssociatedFields.Contains(field.Name)) .ToArray(); // hack: for SingleTable hierarchies mapping name is not set correctly // and always should be taken from hierarchy root var mappingNameSource = source.Hierarchy != null && source.Hierarchy.InheritanceSchema == InheritanceSchema.SingleTable ? source.Hierarchy.Root : source; var result = new StoredTypeInfo { Name = source.Name, UnderlyingType = GetTypeFullName(source.UnderlyingType), TypeId = registry != null?registry.GetTypeId(source) : TypeInfo.NoTypeId, MappingName = mappingNameSource.MappingName, MappingSchema = source.MappingSchema ?? string.Empty, MappingDatabase = source.MappingDatabase ?? string.Empty, IsEntity = source.IsEntity, IsAbstract = source.IsAbstract, IsInterface = source.IsInterface, IsStructure = source.IsStructure, IsSystem = source.IsSystem, AncestorName = sourceAncestor != null ? sourceAncestor.Name : null, Associations = associations, HierarchyRoot = hierarchyRoot, Fields = fields.Select(ConvertField).ToArray(), }; return(result); }
private void UpdateTypeAllDescendants(StoredTypeInfo type) { type.AllDescendants = type.Descendants.Flatten(t => t.Descendants, item => { }, true).ToArray(); }
private void UpdateTypeDescendants(StoredTypeInfo type) { type.Descendants = types.Values .Where(t => t.Ancestor == type) .ToArray(); }