public Keys GetKeys( Microsoft.SqlServer.Management.Smo.Table table )
{
var keys = new Keys();
foreach (Microsoft.SqlServer.Management.Smo.Index index in table.Indexes)
{
var indexType = index.IndexKeyType;
bool isRegularIndex = indexType != IndexKeyType.DriPrimaryKey && indexType != IndexKeyType.DriUniqueKey;
if (isRegularIndex)
continue;
var columns = index.IndexedColumns.Cast<IndexedColumn>()
.Select( indexedColumn => new Column {ColumnName = indexedColumn.Name} )
.ToList();
if (indexType == IndexKeyType.DriPrimaryKey)
{
keys.PrimaryKey = new PrimaryKey
{
Name = index.Name,
Columns = columns,
};
continue;
}
if (indexType == IndexKeyType.DriUniqueKey)
{
keys.UniqueKey = new UniqueKey
{
Name = index.Name,
Columns = columns,
};
}
}
return keys;
}