예제 #1
0
 static void MapAsyncSettings(Method method, DacpacExtractor extractor)
 {
     var map = extractor.AsyncMappings.EmptyIfNull().FirstOrDefault(a => a.IndexName == method.KeyName);
     if (map != null)
     {
         method.ReadAsAsync = map.GetAsync;
         method.WriteAsAsync = map.SaveAsync;
         method.DeleteAsAsync = map.DeleteAsync;
     }
 }
예제 #2
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.ObjectsToIgnore.EmptyIfNull().Contains(ret.TableName))
             {
                 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.ObjectsToIgnore.EmptyIfNull().Contains(ret.TableName))
             {
                 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.ObjectsToIgnore.EmptyIfNull().Contains(ret.TableName))
             {
                 if ((extractor.IncludeNonUniqueIndex && !ret.Unique)
                     || (extractor.IncludeUniqueIndex && ret.Unique))
                 {
                     SqlToCsharpHelper.GetType(entities, ret, false, null);
                     MapAsyncSettings(ret, extractor);
                     yield return ret;
                 }
             }
         }
     }
 }