LinqConnect Documentation
In This Topic
    DataContext Mapping
    In This Topic

    DataContext mapping allows you to specify the database provider for connecting to DBMS and the database (schema) name.

    The Devart.Data.Linq.DataContext class can use different data providers to connect to different DBMSs. Thus, when a DataContext instance is created, it should know what data provider to use, and provider must be specified in one of the ways described below. The assembly of the used provider should be linked to your project. See the following table for the information on provider classes and assemblies to link for the supported databases.

    Database Assembly Class Name
    SQL Server Devart.Data.SqlServer.Linq.dll Devart.Data.SqlServer.Linq.Provider.SqlDataProvider
    Oracle Devart.Data.Oracle.Linq.dll Devart.Data.Oracle.Linq.Provider.OracleDataProvider
    MySQL Devart.Data.MySql.Linq.dll Devart.Data.MySql.Linq.Provider.MySqlDataProvider
    PostgreSQL Devart.Data.PostgreSql.Linq.dll Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider
    SQLite Devart.Data.SQLite.Linq.dll Devart.Data.SQLite.Linq.Provider.SQLiteDataProvider

    Specifying the database name is optional, and this database name will be used only if the connection itself does not specify the database name. If the database name is specified in the connection, the database name, specified in the context mapping, is used only for CreateDatabase/DatabaseExists/DeleteDatabase features. If the database name is not specified in both the context mapping and in the connection, the model database is assumed to have the same name as the context class.

    Attribute Mapping

    When using attribute mapping, you can specify this data provider, by specifying the ProviderAttribute class attribute for your DataContext.


    C#csharpCopy Code
    [ProviderAttribute(typeof(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))]
    [Database(Name="CRM_DEMO")]
    public class MyDataContext : DataContext {
        //...
    }
    Visual BasicCopy Code
    <Provider(GetType(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))> _
    <Database(Name:="CRM_DEMO")> _
    Public Class MyDataContext
        Inherits DataContext
        '...
    End Class
    

    XML Mapping

    Database tag is used for DataContext XML mapping. Its Name attribute defines the schema name and the Provider attribute defines the Provider.

    <Database Name="CRM_DEMO" Provider="Devart.Data.Oracle.Linq.Provider.OracleDataProvider" xmlns="http://schemas.devart.com/linqconnect/mapping">

    Fluent Mapping

    FluentMappingBuilder class methods are used for mapping DataContext. Database provider class instance should be passed as the parameter of the FluentMappingBuilder constructor, and default database is specified using the DefaultSchema method.


    C#csharpCopy Code
    FluentMappingBuilder builder = new FluentMappingBuilder(
        new Devart.Data.Oracle.Linq.Provider.OracleDataProvider()
    );
    builder.DefaultSchema("CRM_DEMO");
    
    Visual BasicCopy Code
    Dim builder As New FluentMappingBuilder(New Devart.Data.Oracle.Linq.Provider.OracleDataProvider())
    builder.DefaultSchema("CRM_DEMO")