Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8c9dd8e

Browse files
committed
Add Generic version of db.TableExists<T>()
1 parent ae9413c commit 8c9dd8e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ServiceStack.OrmLite/OrmLiteWriteConnectionExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ public static bool TableExists(this IDbConnection dbConn, string tableName)
1616
return dbConn.GetDialectProvider().DoesTableExist(dbConn, tableName);
1717
}
1818

19+
/// <summary>
20+
/// Checks whether a Table Exists. E.g:
21+
/// <para>db.TableExists&lt;Person&gt;()</para>
22+
/// </summary>
23+
public static bool TableExists<T>(this IDbConnection dbConn)
24+
{
25+
var dialectProvider = dbConn.GetDialectProvider();
26+
var modelDef = typeof(T).GetModelDefinition();
27+
var tableName = dialectProvider.NamingStrategy.GetTableName(modelDef.ModelName);
28+
return dialectProvider.DoesTableExist(dbConn, tableName);
29+
}
30+
1931
/// <summary>
2032
/// Create DB Tables from the schemas of runtime types. E.g:
2133
/// <para>db.CreateTables(typeof(Table1), typeof(Table2))</para>

0 commit comments

Comments
 (0)