Checks whether a foreign key corresponding to the association exist in the database.

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

Syntax

C#
public static bool ExistsInDB(
	this MetaAssociation association,
	IDbConnection connection
)
Visual Basic (Declaration)
<ExtensionAttribute> _
Public Shared Function ExistsInDB ( _
	association As MetaAssociation, _
	connection As IDbConnection _
) As Boolean
Visual C++
[ExtensionAttribute]
public:
static bool ExistsInDB(
	MetaAssociation^ association, 
	IDbConnection^ connection
)

Parameters

association
Type: System.Data.Linq.Mapping..::.MetaAssociation
Linq-to-SQL MetaAssociation representing the association/foreign key to find in the database.
connection
Type: System.Data..::.IDbConnection
SQL Connection for the database to locate the foreign key in.

Return Value

True if the database contains a foreign key constraint corresponding to the association. False if no corresponding foreign key constraint is defined.

Examples

This example shows how to check whether a foreign key corresponding to an association exists in the database.
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())
        {
            //iterate through the collection of associations
            foreach (System.Data.Linq.Mapping.MetaAssociation association in table.RowType.Associations)
            {
                if (association.ExistsInDB(dc.Connection))
                {
                    //foreign key constraint exists in the database
                }
                else
                {
                    //foreign key constraint does not exist
                }
            }
        }
    }
}

See Also