.net - 是否有用于读取 DACPAC 文件的库?

标签 .net sql-server

我想读取 DACPAC 的内容,以获得架构、表等的列表。

最佳答案

是的。您可以使用DacFx为此。

DacFx Public Model Tutorial :

  // Load from a dacpac
  using (TSqlModel modelFromDacpac = new TSqlModel("mydb.dacpac"))
  {        
      ReadTheModel(modelFromDacpac);
  }

 private static void ReadTheModel(TSqlModel model)
 {
     // This will get all tables. Note the use of Table.TypeClass!
     var tables = model.GetObjects(DacQueryScopes.Default, Table.TypeClass).ToList();

     // Look up a specific table by ID. Note that if no schema is defined when creating 
     // an element the default "dbo" schema is used
     var t1 = model.GetObjects(Table.TypeClass, 
         new ObjectIdentifier("dbo", "t1"), DacQueryScopes.Default).FirstOrDefault();

      // Get a the column referenced by this table, and query its length 
      TSqlObject column = t1.GetReferenced(Table.Columns)
              .First(col => col.Name.Parts[2].Equals("c1"));

      int columnLength = column.GetProperty<int>(Column.Length);
      Console.WriteLine("Column c1 has length {0}", columnLength); 


      // Verify the ColumnType of this column. This can help indicate which 
      // properties will return meaningful values.
      // For instance since Column.Collation is only available on a simple column,
      // and Column.Persisted is only on computed columns
      ColumnType columnType = column.GetMetadata<ColumnType>(Column.ColumnType);
      Console.WriteLine("Column c1 is of type '{0}'", columnType);
  } 

关于.net - 是否有用于读取 DACPAC 文件的库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37266965/

相关文章:

c# - 如何在 C# 中使用 HttpClient 通过 IP 地址启动与服务器的可信 TLS 连接?

c# - 使用 Entity Framework Core 将文件存储在数据库中

c# - 如何按多个字段分组并获取另一个字段的计数

.net - Delphi : How to call the .Net 4.0 版本的 StrongNameSignatureVerificationEx

.net - TimeZoneInfo - 相同的 TimeZoneInfo id,不同的夏令时支持值

c# - 如何将 "AutoSize"设置为 Excel 工作表列? (非营利组织)

sql - 获取由另一列分组然后分组到另一列的列的总和

sql - 为什么 MS SQL 允许创建非法列?

sql - 确定 SQL 数据中特定事件发生的频率和持续时间

c# - 系统.MissingMethodException : Method not found?