<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C.M. Jackson .Net &#187; IQToolkit</title>
	<atom:link href="http://www.cmjackson.net/tag/iqtoolkit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cmjackson.net</link>
	<description>Web Design, Programming, Tutorials</description>
	<lastBuildDate>Tue, 13 Dec 2011 17:38:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Using the Linq IQueryable Toolkit</title>
		<link>http://www.cmjackson.net/2010/02/10/using-the-linq-iqueryable-toolkit/</link>
		<comments>http://www.cmjackson.net/2010/02/10/using-the-linq-iqueryable-toolkit/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:14:45 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[IQToolkit]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=385</guid>
		<description><![CDATA[The IQToolkit provides you with a framework for building your own LINQ providers. The toolkit comes with providers for Microsoft SQL, Microsoft SQL CE, Access, MySQL, and SQLite. This post will show you how to use the toolkit to talk to Microsoft SQL. Later, I&#8217;ll be attempting to write my own providers for DB2 and [...]]]></description>
			<content:encoded><![CDATA[<p>The IQToolkit provides you with a framework for building your own LINQ providers. The toolkit comes with providers for Microsoft SQL, Microsoft SQL CE, Access, MySQL, and SQLite.</p>
<p>This post will show you how to use the toolkit to talk to Microsoft SQL. Later, I&#8217;ll be attempting to write my own providers for DB2 and Interbase 7.1.</p>
<p><strong>Download the toolkit</strong><br />
First thing to do is <a href="http://www.codeplex.com/IQToolkit">download the IQToolkit</a> (version 0.16a as of this posting).</p>
<p><strong>Reference the toolkit</strong><br />
I setup a console project to test the toolkit. Within your project, create a reference to the IQToolkit.Data.dll and the IQToolkit.dll. Then, add a reference to the dll for the provider you wish to use. In this case, we are using the IQToolkit.Data.SqlClient.dll for Microsoft SQL.</p>
<p><strong>Table objects</strong><br />
Next, you will need to create a class object for each table you need to work with in the database. I have a table that has two fields: PLCID and SummaryProdMode. Create a class object to hold these properties and then use the Column attribute to bind the property to the table column.</p>
<pre class="brush: vb;">
Imports IQToolkit.Data.Mapping

Public Class Machine

    Private _id As Integer
    Private _mode As Boolean

    &lt;Column(IsPrimaryKey:=True)&gt; _
    Public Property PLCID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    &lt;Column()&gt; _
    Public Property SummaryProdMode() As Boolean
        Get
            Return _mode
        End Get
        Set(ByVal value As Boolean)
            _mode = value
        End Set
    End Property

End Class
</pre>
<p><strong>DataContext</strong><br />
The data context contains read only properties for each database table being used. In this case, I&#8217;m dealing with the DCM_Machines table.</p>
<pre class="brush: vb;">
Imports IQToolkit
Imports IQToolkit.Data.Mapping
Imports System.Linq

Public Class MachineDataContext

    Private _provider As IEntityProvider

    Public Property EntityProvider() As IEntityProvider
        Get
            Return _provider
        End Get
        Set(ByVal value As IEntityProvider)
            _provider = value
        End Set
    End Property

    &lt;Table()&gt; _
    Public ReadOnly Property Machines() As IEntityTable(Of Machine)
        Get
            Return EntityProvider.GetTable(Of Machine)(&quot;DCM_Machines&quot;)
        End Get
    End Property

    Public Sub New(ByVal provider As IEntityProvider)

        _provider = provider

    End Sub

End Class
</pre>
<p><strong>Using the provider</strong><br />
Use the following code to setup and use the provider with LINQ.</p>
<pre class="brush: vb;">
Imports IQToolkit.Data

Module Module1

    Sub Main()

        Dim provider = DbEntityProvider.From( _
            &quot;IQToolkit.Data.SqlClient&quot;, _
            &quot;YOUR_CONNECTION_STRING&quot;, _
            &quot;Machine&quot;)
        Dim db = New MachineDataContext(provider)

        Dim machs = (From m In db.Machines _
                    Select m).ToList()

        For Each m In machs

            Console.WriteLine(&quot;id=&quot; &amp; m.PLCID)

        Next

        Console.ReadLine()

    End Sub

End Module
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2010/02/10/using-the-linq-iqueryable-toolkit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

