Drop the primary key (and any FKs referring to it) for a table if the definition does not match the primary key definition in the Linq-to-SQL model.

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

Syntax

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

Parameters

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

Examples

This example shows how to drop primary keys if they do not correspond to the model-defined PK:
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())
        {
            //drop the primary key if it does not correspond to the model definition.
            table.DropPKIfIncorrect(dc.Connection);
        }
    }
}

See Also