Checks whether a database index complementing the foreign key/association exist in the database.

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

Syntax

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

Parameters

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

Return Value

True if there is an index complementing the association, false if not.

Examples

This example shows how to check whether an index complementing 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.IsForeignKey && association.IsIndexed(dc.Connection))
                {
                    //an index complementing the association/foreign key constraint exists in the database
                }
                else
                {
                    //no complementing index was found
                }
            }
        }
    }
}

See Also