gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:12:18 26 4
gpt4 key购买 nike

我想阅读 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com