Create primary key on table if it is missing in the database.

Namespace:  Huagati.DBMLTools.Runtime
Assembly:  HuagatiDBMLToolsRTE (in HuagatiDBMLToolsRTE.dll) Version: 1.66.3362.23798

Syntax

C#
public static void CreateMissingPK(
	this MetaTable table,
	IDbConnection connection
)
Visual Basic (Declaration)
<ExtensionAttribute> _
Public Shared Sub CreateMissingPK ( _
	table As MetaTable, _
	connection As IDbConnection _
)
Visual C++
[ExtensionAttribute]
public:
static void CreateMissingPK(
	MetaTable^ table, 
	IDbConnection^ connection
)

Parameters

table
Type: System.Data.Linq.Mapping..::.MetaTable
Linq-to-SQL MetaTable object for the table to add primary key to.
connection
Type: System.Data..::.IDbConnection
Database connection.

Examples

This example shows how to add primary keys to tables referenced by a Linq-to-SQL datacontext:
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())
        {
            //create primary key if missing
            table.CreateMissingPK(dc.Connection);
        }
    }
}

See Also