Skip to content

Commit a68e536

Browse files
committed
remove table creator dependency on "id" column name
1 parent 91cb3c9 commit a68e536

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/SqlTableCreator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ private static string GetSqlFromDataTable(string tableName, DataTable table, str
4545

4646
// columns
4747
bool hasPrimaryKey = false;
48-
bool clusteredIndex = true;
4948
int numOfColumns = table.Columns.Count;
5049
int i = 1;
5150
foreach (DataColumn column in table.Columns)
5251
{
5352
sql.AppendFormat("[{0}] {1}", column.ColumnName, SqlGetType(column));
54-
if (column.ColumnName.ToUpper().Equals("ID") || column.AutoIncrement)
53+
if (column.AutoIncrement) // the PK is always auto-increment (IDENTITY)
5554
{
5655
hasPrimaryKey = true;
57-
clusteredIndex = (bool)column.ExtendedProperties["clusteredIndex"];
5856
sql.Append(" IDENTITY(1,1) ");
5957
}
6058
if (numOfColumns > i)
@@ -65,6 +63,7 @@ private static string GetSqlFromDataTable(string tableName, DataTable table, str
6563
// primary keys
6664
if (hasPrimaryKey)
6765
{
66+
var clusteredIndex = (bool)table.PrimaryKey[0].ExtendedProperties["clusteredIndex"];
6867
sql.AppendFormat(" CONSTRAINT [PK_{0}] PRIMARY KEY {1}CLUSTERED (", tableName, clusteredIndex ? string.Empty : "NON" );
6968

7069
int numOfKeys = table.PrimaryKey.Length;

0 commit comments

Comments
 (0)