Adds foreign keys to the table if not present in the database.

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

Syntax

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

Parameters

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

Examples

This example shows how to add missing foreign key constraints for all tables defined in a datacontext. Complementing indexes will be created automatically.
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())
        {
            //add missing foreign key constraints
            table.AddMissingFKs(dc.Connection);
        }
    }
}

See Also