Exemple #1
0
        public static IProjectSchemaElement GetElementForXElement(Project project, ElementType elementType, XElement element)
        {
            string elementName = GetNameForElement(elementType, element);

            if (elementType == ElementType.Table)
            {
                return(project.FindTableMapping(element.Attribute("ConnectionName").Value, element.Attribute("SchemaName").Value, elementName));
            }
            else if (elementType == ElementType.ForeignKey)
            {
                return(project.FindForeignKeyMapping(element.Attribute("ConnectionName").Value, elementName));
            }
            else
            {
                string       parentElementName = GetNameForParentElement(elementType, element);
                string       connectionName    = ((XAttribute)element.XPathEvaluate("ancestor::TableMapping/@ConnectionName")).Value;
                string       schemaName        = ((XAttribute)element.XPathEvaluate("ancestor::TableMapping/@SchemaName")).Value;
                TableMapping tableMapping      = project.FindTableMapping(connectionName, schemaName, parentElementName);

                if (elementType == ElementType.Column)
                {
                    return(tableMapping.FindColumnMapping(elementName));
                }
                else if (elementType == ElementType.UniqueIndex)
                {
                    return(tableMapping.FindUniqueIndexMapping(elementName));
                }
                else if (elementType == ElementType.API)
                {
                    return(tableMapping.FindAPI(elementName));
                }
            }

            throw new ApplicationException("Unhandled TemplateOutputDefinitionElementType of \"{0}.\"".FormatString(elementType));
        }