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,
	bool createIndexesForFKs
)
Visual Basic (Declaration)
<ExtensionAttribute> _
Public Shared Sub AddMissingFKs ( _
	table As MetaTable, _
	connection As IDbConnection, _
	createIndexesForFKs As Boolean _
)
Visual C++
[ExtensionAttribute]
public:
static void AddMissingFKs(
	MetaTable^ table, 
	IDbConnection^ connection, 
	bool createIndexesForFKs
)

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.
createIndexesForFKs
Type: System..::.Boolean
Boolean flag controlling whether to create indexes corresponding to the foreign key constraint or not.

Examples

This example shows how to missing foreign key constraints for all tables defined in a 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())
        {
            //add missing foreign key constraints, but no complementing indexes
            table.AddMissingFKs(dc.Connection, false);
        }
    }
}

See Also