Implementing my own DataContext class

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
chadm
Posts: 2
Joined: Wed 21 Dec 2005 20:53

Implementing my own DataContext class

Post by 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)
            MyBase.New(inCnStr)
        End Sub

        Public Sub New(ByVal inDatabaseConnection As IDbConnection)
            MyBase.New(inDatabaseConnection)
        End Sub


        Public Customers As Table(Of Customer)

    End Class

     _
    Public Class Customer

        Private mCustomerID As String = String.Empty
         _
        Public Property CustomerID() As String
            Get
                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
            Get
                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=127.0.0.1;Database=test;Pooling=True"
        Dim ctx As MyDataContext = New MyDataContext(cn)
        Dim i As Integer = 0

        cn.ConnectionString = cnStr

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

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

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

        Console.ReadLine()

    End Sub

End Module

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 26 Aug 2008 16:55

You can download our solution for LINQ to MySQL support here:

http://www.devart.com/mysqlnet/download.html

Post Reply