Checks whether the data type for a table column correspond to the data type declared in the model.

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

Syntax

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

Parameters

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

Return Value

True if the data type in the database is identical to the declared datatype in the model, false if not.

Examples

This example shows how to check whether a column corresponding to a Linq-to-SQL entity class member has the same datatype in the database as in the model.
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 data type in the database
                    if (member.HasCorrectDBType(dc.Connection))
                    {
                        //the database column has the same data type as the entity member in the model
                    }
                    else
                    {
                        //data types don't match
                    }
                }
            }
        }
    }
}

See Also