Beispiel #1
0
        public RelationshipList GetRelationshipList(string relationshipListName)
        {
            if (!relationshipListName.Contains("."))
            {
                return(PrivateGetRelationshipList(relationshipListName));
            }

            SchemaObject finalSchemaObject = GetFinalSchemaObject(relationshipListName);

            return(finalSchemaObject.PrivateGetRelationshipList(relationshipListName.Substring(relationshipListName.LastIndexOf(".") + 1)));
        }
Beispiel #2
0
        public Field GetField(string fieldName)
        {
            if (fieldName == null)
            {
                return(null);
            }

            if (!fieldName.Contains("."))
            {
                return(PrivateGetField(fieldName));
            }

            SchemaObject finalSchemaObject = GetFinalSchemaObject(fieldName);

            return(finalSchemaObject.PrivateGetField(fieldName.Substring(fieldName.LastIndexOf(".") + 1)));
        }
Beispiel #3
0
        private SchemaObject GetFinalSchemaObject(string path)
        {
            string[]     parts            = path.Split('.');
            SchemaObject lastSchemaObject = this;

            for (int i = 1; i < parts.Length - 1; i++)
            {
                Relationship relationship = lastSchemaObject.PrivateGetRelationship(parts[i]);
                if (relationship == null)
                {
                    throw new KeyNotFoundException($"Could not find relationship {parts[i]} on Data Object {lastSchemaObject.SchemaName}.{lastSchemaObject.ObjectName}");
                }

                lastSchemaObject = Schema.GetSchemaObject(relationship.RelatedObjectType);
            }

            return(lastSchemaObject);
        }
Beispiel #4
0
        private Schema()
        {
            foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes().Where(t => t.GetCustomAttribute <TableAttribute>() != null)))
            {
                SchemaObject newSchemaObject = new SchemaObject(type);

                schemaObjects.Add(newSchemaObject);
                schemaObjectsByType.Add(type, newSchemaObject);
                schemaObjectsBySchemaObjectNames.GetOrSet(newSchemaObject.SchemaName, () => new Dictionary <string, SchemaObject>()).GetOrSet(newSchemaObject.ObjectName, () => newSchemaObject);
            }

            foreach (SchemaObject schemaObject in schemaObjects)
            {
                foreach (Relationship relationship in schemaObject.GetRelationships())
                {
                    relationship.RelatedSchemaObject = schemaObjectsByType[relationship.RelatedObjectType];
                    relationship.ParentKeyField      = relationship.RelatedSchemaObject.GetField(relationship.RelationshipAttribute.ParentKeyField) ?? relationship.RelatedSchemaObject.PrimaryKeyField;
                }
            }
        }