Returns a SQL-DDL create index statement for an index corresponding to a Linq-to-SQL MetaAssociation.
Namespace:
Huagati.DBMLTools.RuntimeAssembly: HuagatiDBMLToolsRTE (in HuagatiDBMLToolsRTE.dll) Version: 1.66.3362.23798
Syntax
C# |
---|
public static string AddIndexStatement( this MetaAssociation association ) |
Visual Basic (Declaration) |
---|
<ExtensionAttribute> _ Public Shared Function AddIndexStatement ( _ association As MetaAssociation _ ) As String |
Visual C++ |
---|
[ExtensionAttribute] public: static String^ AddIndexStatement( MetaAssociation^ association ) |
Parameters
- association
- Type: System.Data.Linq.Mapping..::.MetaAssociation
Association to create an index for.
Return Value
SQL-DDL 'create index' statement for creating an index complementing a foreign key/association.
Examples
This example shows how to check whether a foreign key corresponding to an association exists in the database, and generate SQL-DDL for adding missing constraints.
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)) { //generate 'create index' statement string createIndex = association.AddIndexStatement(); } } } } }