Checks whether a column corresponding to an entity member 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 MetaDataMember member,
	IDbConnection connection
)
Visual Basic (Declaration)
<ExtensionAttribute> _
Public Shared Function ExistsInDB ( _
	member As MetaDataMember, _
	connection As IDbConnection _
) As Boolean
Visual C++
[ExtensionAttribute]
public:
static bool ExistsInDB(
	MetaDataMember^ member, 
	IDbConnection^ connection
)

Parameters

member
Type: System.Data.Linq.Mapping..::.MetaDataMember
Linq-to-SQL MetaDataMember representing the column to find in the database.
connection
Type: System.Data..::.IDbConnection
SQLConnection object for the database to locate the column in.

Return Value

True if the column exists, false if not.

Examples

This example shows how to check whether a column corresponding to a Linq-to-SQL entity class member 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 members
            foreach (System.Data.Linq.Mapping.MetaDataMember member in table.RowType.DataMembers)
            {
                //only check non-association persistent members
                if (!member.IsAssociation && member.IsPersistent)
                {
                    //check if member column exists in the database
                    if (member.ExistsInDB(dc.Connection))
                    {
                        //column exists in the database
                    }
                    else
                    {
                        //no column corresponding to the entity member was found in the database
                    }
                }
            }
        }
    }
}

See Also