<?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>Schotime.net &#187; Linq C# MySql</title>
	<atom:link href="http://schotime.net/blog/index.php/tag/linq-c-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://schotime.net/blog</link>
	<description>All Things .Net and Me</description>
	<lastBuildDate>Thu, 01 Jul 2010 14:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Retrieving Data Without the Dataset With Custom SQL</title>
		<link>http://schotime.net/blog/index.php/2009/02/12/retrieving-data-without-the-dataset-with-custom-sql/</link>
		<comments>http://schotime.net/blog/index.php/2009/02/12/retrieving-data-without-the-dataset-with-custom-sql/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 10:38:16 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Linq C# MySql]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2009/02/12/retrieving-data-without-the-dataset-with-custom-sql/</guid>
		<description><![CDATA[In my previous post I used custom sql query and transformed the results into a nested class. However you may have overlooked way I got the data into a class. It quite easy and will work with all database connectors that implement IDbConnection.
Here is how its done. We use the DataContext that came with and [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post I used custom sql query and transformed the results into a nested class. However you may have overlooked way I got the data into a class. It quite easy and will work with all database connectors that implement IDbConnection.</p>
<p>Here is how its done. We use the DataContext that came with and used by Linq2Sql.</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td style="background: black" valign="top" width="400">
<pre class="code"><span style="background: black; color: white">        </span><span style="background: black; color: #cc7832">public class </span><span style="background: black; color: #ffc66d">RawData
        </span><span style="background: black; color: white">{
            </span><span style="background: black; color: #cc7832">public int </span><span style="background: black; color: white">MyId { </span><span style="background: black; color: #cc7832">get</span><span style="background: black; color: white">; </span><span style="background: black; color: #cc7832">set</span><span style="background: black; color: white">; }
            </span><span style="background: black; color: #cc7832">public string </span><span style="background: black; color: white">Name { </span><span style="background: black; color: #cc7832">get</span><span style="background: black; color: white">; </span><span style="background: black; color: #cc7832">set</span><span style="background: black; color: white">; }
        }</span></pre>
</td>
</tr>
</tbody>
</table>
<p></p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td style="background: black" valign="top" width="400">
<pre class="code"><span style="background: black; color: white"></span><span style="background: black; color: white"></span></pre>
<pre class="code"><span style="background: black; color: white">        </span><span style="background: black; color: #ffc66d">DataContext </span><span style="background: black; color: white">dc = </span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: #ffc66d">DataContext</span><span style="background: black; color: white">(</span><span style="background: black; color: #cc7832">new </span><span style="background: black; color: white">MySqlConnection(connString));
        </span><span style="background: black; color: #6897bb">IEnumerable</span><span style="background: black; color: white">&lt;</span><span style="background: black; color: #ffc66d">RawData</span><span style="background: black; color: white">&gt; rd =
            dc.ExecuteQuery&lt;</span><span style="background: black; color: #ffc66d">RawData</span><span style="background: black; color: white">&gt;(</span><span style="background: black; color: #a5c25c">"select myid, name from mytable where myid &gt; ?"</span><span style="background: black; color: white">,5);</span></pre>
<p><a href="http://11011.net/software/vspaste" onclick="pageTracker._trackPageview('/outgoing/11011.net/software/vspaste?referer=');"></a></td>
</tr>
</tbody>
</table>
<p>And thats it. All the data from the mytable database table will get pushed into the IEnumerable&lt;RawData&gt; variable. As long as the names of the columns are the same as the class then this will work. This ExecuteQuery method also takes a parameters object argument which will replace the question marks with the variables specified.</p>
<p>It makes it very easy, especially since there isn&#8217;t a very good linq 2 mysql option out there yet and Entity Framework still doesn&#8217;t support it.</p>
<p>Cheers,<br />Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2009/02/12/retrieving-data-without-the-dataset-with-custom-sql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
