private static IEnumerable <StoredProcedure> GetParamedDbos(string type, XElement xml, DacpacExtractor extractor)
        {
            string xpath    = "/DataSchemaModel/Model/Element[@Type='{0}']".FormatInvariantCulture(type);
            var    elements = xml.XPathSelectElements(xpath);

            foreach (var element in elements)
            {
                var ret = new StoredProcedure
                {
                    Name   = element.GetAttributeString("Name"),
                    Params =
                        element.XPathSelectElements(
                            "Relationship[@Name='Parameters']/Entry/Element[@Type='SqlSubroutineParameter']")
                        .Select(e => new EntityProperty()
                    {
                        Name = e.GetAttributeString("Name"), Type = e.XPathSelectElement("Relationship[@Name='Type']/Entry/Element[@Type='SqlTypeSpecifier' or @Type='SqlXmlTypeSpecifier']/Relationship[@Name='Type']/Entry/References").GetAttributeString("Name")
                    })
                        .ToList()
                };
                if (!extractor.IsIgnored(ret.Name))
                {
                    yield return(ret);
                }
            }
        }
Exemple #2
0
        public static IEnumerable <Entity> GetEntities(XElement xml, DacpacExtractor extractor)
        {
            const string xpath    = "/DataSchemaModel/Model/Element[@Type='SqlTable']";
            var          elements = xml.XPathSelectElements(xpath);

            foreach (var e in elements)
            {
                var entity = new Entity {
                    TableName         = e.GetAttributeString("Name"),
                    IncludeForeignKey = extractor.IncludeForeignKey,
                    ClassAccess       = extractor.ClassAccess ?? "public"
                };
                foreach (var pe in e.XPathSelectElements("Relationship[@Name='Columns']/Entry/Element[@Type='SqlSimpleColumn']"))
                {
                    var nullableNode = pe.XPathSelectElement("Property[@Name='IsNullable']");
                    var identityNode = pe.XPathSelectElement("Property[@Name='IsIdentity']");
                    var p            = new EntityProperty()
                    {
                        Nullable = nullableNode == null || nullableNode.GetAttributeBool("Value"),
                        Identity = identityNode != null && identityNode.GetAttributeBool("Value"),
                        Name     = pe.GetAttributeString("Name"),
                        Type     = pe.XPathSelectElement("Relationship[@Name='TypeSpecifier']/Entry/Element[@Type='SqlTypeSpecifier' or @Type='SqlXmlTypeSpecifier']/Relationship[@Name='Type']/Entry/References").GetAttributeString("Name"),
                    };
                    var over = extractor.ColumnOverrides.EmptyIfNull().FirstOrDefault(o => o.Name == p.Name);
                    if (over != null)
                    {
                        p.Type       = over.Type ?? p.Type;
                        p.Nullable   = over.Nullable ?? p.Nullable;
                        p.Attributes = over.Attributes;
                        over.Name    = null;
                    }

                    if (p.Type.ToLower() != "[timestamp]" && p.Type.ToLower() != "[rowversion]" && !extractor.IsIgnored(p.Name))
                    {
                        entity.Properties.Add(p);
                    }
                }
                foreach (var c in extractor.ColumnOverrides.EmptyIfNull())
                {
                    if (c.Name != null && c.Type != null && c.Name.StartsWith(entity.TableName))
                    {
                        entity.Properties.Add(c);
                    }
                }
                var an = extractor.EntityOverrides.EmptyIfNull().FirstOrDefault(ae => ae.TableName == entity.TableName);
                if (an != null)
                {
                    entity.Annotations       = an.Annotations;
                    entity.Name              = an.Name;
                    entity.IncludeForeignKey = an.IncludeForeignKey;
                    entity.ClassAccess       = an.ClassAccess.IsNullOrWhiteSpace() ? entity.ClassAccess : an.ClassAccess;
                }
                if (!extractor.ObjectsToIgnore.EmptyIfNull().Contains(entity.TableName))
                {
                    yield return(entity);
                }
            }
        }
Exemple #3
0
 public static IEnumerable <Method> GetMethods(XElement xml, DacpacExtractor extractor, IList <Entity> entities)
 {
     if (extractor.IncludeForeignKey)
     {
         var elements = xml.XPathSelectElements("/DataSchemaModel/Model/Element[@Type='SqlForeignKeyConstraint']");
         foreach (var element in elements)
         {
             var foreignTable = element.XPathSelectElement("Relationship[@Name='ForeignTable']/Entry/References")
                                .GetAttributeString("Name");
             var ps = element.XPathSelectElements("Relationship[@Name='Columns']/Entry/References")
                      .Select(e => new EntityProperty()
             {
                 Name = e.GetAttributeString("Name")
             }).ToList();
             for (int index = 0; index < ps.Count; index++)
             {
                 var property = ps[index];
                 property.ForeignName =
                     element.XPathSelectElement("Relationship[@Name='ForeignColumns']/Entry[" + (index + 1) + "]/References")
                     .GetAttributeString("Name");
             }
             var ret = new Method
             {
                 TableName =
                     element.XPathSelectElement("Relationship[@Name='DefiningTable']/Entry/References")
                     .GetAttributeString("Name"),
                 Params        = ps,
                 KeyName       = element.GetAttributeString("Name"),
                 ReadAsAsync   = extractor.GetAsync,
                 DeleteAsAsync = extractor.DeleteAsync,
                 WriteAsAsync  = extractor.SaveAsync
             };
             if (!extractor.IsIgnored(ret.TableName) && !extractor.IsIgnored(ret.KeyName))
             {
                 SqlToCsharpHelper.GetType(entities, ret, false, foreignTable);
                 MapAsyncSettings(ret, extractor);
                 yield return(ret);
             }
         }
     }
     if (extractor.IncludePrimaryKey)
     {
         var elements = xml.XPathSelectElements("/DataSchemaModel/Model/Element[@Type='SqlPrimaryKeyConstraint']");
         foreach (var element in elements)
         {
             var ret = new Method
             {
                 KeyName   = element.GetAttributeString("Name"),
                 TableName =
                     element.XPathSelectElement("Relationship[@Name='DefiningTable']/Entry/References")
                     .GetAttributeString("Name"),
                 Unique = true,
                 Params =
                     element.XPathSelectElements(
                         "Relationship[@Name='ColumnSpecifications']/Entry/Element[@Type='SqlIndexedColumnSpecification']/Relationship[@Name='Column']/Entry/References")
                     .Select(e => new EntityProperty()
                 {
                     Name = e.GetAttributeString("Name")
                 })
                     .ToList(),
                 ReadAsAsync   = extractor.GetAsync,
                 DeleteAsAsync = extractor.DeleteAsync,
                 WriteAsAsync  = extractor.SaveAsync
             };
             if (!extractor.IsIgnored(ret.TableName) && !extractor.IsIgnored(ret.KeyName))
             {
                 SqlToCsharpHelper.GetType(entities, ret, true, null);
                 MapAsyncSettings(ret, extractor);
                 yield return(ret);
             }
         }
     }
     if (extractor.IncludeNonUniqueIndex || extractor.IncludeUniqueIndex)
     {
         var elements = xml.XPathSelectElements("/DataSchemaModel/Model/Element[@Type='SqlIndex']");
         foreach (var element in elements)
         {
             var uniqueNode = element.XPathSelectElement("Property[@Name='IsUnique']");
             var ret        = new Method
             {
                 TableName =
                     element.XPathSelectElement("Relationship[@Name='IndexedObject']/Entry/References")
                     .GetAttributeString("Name"),
                 Unique = uniqueNode != null && uniqueNode.GetAttributeBool("Value"),
                 Params =
                     element.XPathSelectElements(
                         "Relationship[@Name='ColumnSpecifications']/Entry/Element[@Type='SqlIndexedColumnSpecification']/Relationship[@Name='Column']/Entry/References")
                     .Select(e => new EntityProperty()
                 {
                     Name = e.GetAttributeString("Name")
                 })
                     .ToList(),
                 KeyName       = element.GetAttributeString("Name"),
                 ReadAsAsync   = extractor.GetAsync,
                 DeleteAsAsync = extractor.DeleteAsync,
                 WriteAsAsync  = extractor.SaveAsync
             };
             if (!extractor.IsIgnored(ret.TableName) && !extractor.IsIgnored(ret.KeyName))
             {
                 if ((extractor.IncludeNonUniqueIndex && !ret.Unique) ||
                     (extractor.IncludeUniqueIndex && ret.Unique))
                 {
                     SqlToCsharpHelper.GetType(entities, ret, false, null);
                     MapAsyncSettings(ret, extractor);
                     yield return(ret);
                 }
             }
         }
     }
 }