Data Access has been discontinued. Please refer to this page for more information.

How to: Create A Model Based on MariaDB Database

This topic will walk you through the common task of creating a new Telerik Data Access model connected to a MariaDB database.

To use MariaDB with Telerik Data Access, make sure you have installed Connector/Net driver for MySQL. Telerik Data Access supports only the Connector/Net driver.

  1. Open Microsoft Visual Studio 2010 in elevated administrator mode.
  2. From the File menu, choose New and then Project.
  3. In the New Project dialog, expand the language of your preference. Select Windows and then select Class Library. Type GettingStartedMariaDb for a name of your project.
  4. Integrate the project with the Telerik.DataAccess.Fluent NuGet package.
  5. In the App.config file, add a connection string to your MariaDB database:

    <add name="MariaDbConnection" 
         providerName="MySql.Data.MySqlClient" />
  6. Create POCO classes for the persistent classes.

  7. Using the Fluent Mapping API create the metadatasource class where the mapping is defined.
  8. Create your context class:

    1. Configure the backend to be MySql and to use the MySql.Data.MySqlClient provider.

        private static BackendConfiguration backend = 
        public static BackendConfiguration GetBackendConfiguration()
            BackendConfiguration backend = new BackendConfiguration();
            backend.Backend = "MySql";
            backend.ProviderName = "MySql.Data.MySqlClient";
            CustomizeBackendConfiguration(ref backend);
            return backend;
        Private Shared backend As BackendConfiguration = 
        Public Shared Function GetBackendConfiguration() As BackendConfiguration
            Dim backend As BackendConfiguration = New BackendConfiguration()
            backend.Backend = "MySql"
            backend.ProviderName = "MySql.Data.MySqlClient"
            Return backend
        End Function
    2. Add the name of the connection string:

        private static string connectionStringName = @"MariaDbConnection";
        Private Shared connectionStringName As String = "MariaDbConnection"
    3. Create a new instance of your FluentMetadataSource class that holds the mapping:

        private static MetadataSource metadataSource = 
            new MyModelFluentMetadataSource();
        Private Shared metadataSource As MetadataSource = 
            New MyModelFluentMetadataSource()
    4. Create a constructor for the context:

        public MyModel()
            :base(connectionStringName, backend, metadataSource)
        { }
        Public Sub New()
            MyBase.New(connectionStringName, backend, metadataSource)
        End Sub
    5. Expose the persistent classes through read-only IQueryable<T> properties of the context:

        public IQueryable<MyClass> MyClasses 
                return this.GetAll<MyClass>();
        Public ReadOnly Property MyClasses() As  IQueryable(Of MyClass)
                Return Me.GetAll(Of MyClass)()
            End Get
        End Property