在 SSDT 项目中,使用 DacFx API,我正在查询数据库的内存模型。我一直在尝试检索列的类型,但无法弄清楚。知道如何做到这一点吗?
private void TestMethod()
{
using(TSqlModel model =
new TSqlModel(SqlServerVersion.Sql110, new TSqlModelOptions {}))
{
string[] scripts = new[]
{
"CREATE TABLE t1 (c1 NVARCHAR(30) NOT NULL)",
"CREATE TABLE t2 (c2 INT NOT NULL)"
};
foreach (string script in scripts)
{
model.AddObjects(script);
}
var tables = model.GetObjects(DacQueryScopes.All, Table.TypeClass);
var cols = tables.First().GetReferenced(Table.Columns);
foreach (TSqlObject col in cols)
{
//?? how can I get the data type of the column?
string dataType = col.??;
if (dataType == "int")
{
//my thing here
}
}
}
}