Implementing my own DataContext class

Implementing my own DataContext class

Postby chadm » Tue 26 Aug 2008 16:17

I am tring to implement my own DataContext class by inheriting from System.Data.Linq.DataContext class. I initiate the class by passing in a MySQL connection. The problem is when I try to query, the query is being generated in the wrong format (MSSQL). How do I go about making the datacontext class generate valid MySQL sql syntex?

Code: Select all
Imports System.Data
Imports System.Data.Linq
Imports System.Data.Common
Imports System.Transactions

Module Module1

    Public Class MyDataContext : Inherits DataContext

        Public Sub New(ByVal inCnStr As String)
        End Sub

        Public Sub New(ByVal inDatabaseConnection As IDbConnection)
        End Sub

        Public Customers As Table(Of Customer)

    End Class

    Public Class Customer

        Private mCustomerID As String = String.Empty
        Public Property CustomerID() As String
                Return mCustomerID
            End Get
            Set(ByVal value As String)
                mCustomerID = value
            End Set
        End Property

        Private mCustomerName As String = String.Empty
        Public Property CustomerName() As String
                Return mCustomerName
            End Get
            Set(ByVal value As String)
                mCustomerName = value
            End Set
        End Property

    End Class

    Sub Main()

        Dim mySqlDirectProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory("MySQLDirect.NET Data Provider")
        Dim cn As IDbConnection = mySqlDirectProviderFactory.CreateConnection()
        Dim cnStr As String = "User Id=usr;Password=pwd;Host=;Database=test;Pooling=True"
        Dim ctx As MyDataContext = New MyDataContext(cn)
        Dim i As Integer = 0

        cn.ConnectionString = cnStr

            ctx.Log = Console.Out
            For Each c As Customer In ctx.Customers
                Console.WriteLine(c.CustomerID & "," & c.CustomerName)

            'Console.WriteLine("Rows affected: " & i.ToString)

        Catch ex As Exception
            Console.WriteLine("ERROR: " & ex.Message)
        End Try


    End Sub

End Module
Posts: 2
Joined: Wed 21 Dec 2005 20:53

Postby Shalex » Tue 26 Aug 2008 16:55

You can download our solution for LINQ to MySQL support here:
Devart Team
Posts: 7285
Joined: Thu 14 Aug 2008 12:44

Return to dotConnect for MySQL