Checks if the primary key for a table exist in the database. Does not validate if the primary key matches the model definition; see MetaTable.PKMembersCorrect method.
Namespace:
Huagati.DBMLTools.RuntimeAssembly: HuagatiDBMLToolsRTE (in HuagatiDBMLToolsRTE.dll) Version: 1.66.3362.23798
Syntax
C# |
---|
public static bool PKExistsInDB( this MetaTable table, IDbConnection connection ) |
Visual Basic (Declaration) |
---|
<ExtensionAttribute> _ Public Shared Function PKExistsInDB ( _ table As MetaTable, _ connection As IDbConnection _ ) As Boolean |
Visual C++ |
---|
[ExtensionAttribute] public: static bool PKExistsInDB( MetaTable^ table, IDbConnection^ connection ) |
Parameters
- table
- Type: System.Data.Linq.Mapping..::.MetaTable
Linq-to-SQL MetaTable object for the table to check the primary key for.
- connection
- Type: System.Data..::.IDbConnection
Database connection.
Return Value
true if the primary key exists, false if it is missing.
Examples
This example shows how to check if a table has a primary key defined.
CopyC#

using Huagati.DBMLTools.Runtime; public class MappingSample { public void Test() { SomeDataContext dc = new SomeDataContext(); //iterate through the collection of tables defined in the datacontext foreach (System.Data.Linq.Mapping.MetaTable table in dc.Mapping.GetTables()) { //check if the table has a primary key (without checking if the PK definition matches the model) if (table.PKExistsInDB(dc.Connection)) { //the table has a primary key defined in the database } else { //the table has no primary key in the database } } } }