<?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>MyVerbalOutlet &#187; linq-to-sql</title>
	<atom:link href="http://www.myverbaloutlet.net/tag/linq-to-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.myverbaloutlet.net</link>
	<description>This is where I spout off about stuff</description>
	<lastBuildDate>Tue, 31 Aug 2010 16:05:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>LINQ to SQL DataContext and Transactions</title>
		<link>http://www.myverbaloutlet.net/2009/09/linq-to-sql-datacontext-and-transactions/</link>
		<comments>http://www.myverbaloutlet.net/2009/09/linq-to-sql-datacontext-and-transactions/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 19:00:49 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linq-to-sql]]></category>

		<guid isPermaLink="false">http://www.myverbaloutlet.net/2009/09/linq-to-sql-datacontext-and-transactions/</guid>
		<description><![CDATA[I am posting this as a way to remember it, since I am starting a real project using LINQ to SQL soon. LINQ to SQL orders the objects with pending changes based on their dependencies. LINQ to SQL starts a transaction to wrap the SQL statements. The SQL statements are issued one by one. Any [...]]]></description>
			<content:encoded><![CDATA[<p>I am posting this as a way to remember it, since I am starting a real project using LINQ to SQL soon.</p>
<p>LINQ to SQL orders the objects with pending changes based on their dependencies. LINQ to SQL starts a transaction to wrap the SQL statements. The SQL statements are issued one by one. Any errors detected by the database cause the process to stop and all the changes are rolled back. The DataContext still contains the pending changes enabling you to try and resolve the issue and SubmitChanges again as in this example.</p>
<div id="codeSnippetWrapper" style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; cursor: text; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;">
<div id="codeSnippet" style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum1" style="color: #606060">   1:</span> Northwnd db = <span style="color: #0000ff">new</span> Northwnd(<span style="color: #006080">@"c:\northwnd.mdf"</span>);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #008000">// Make changes here. </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">try</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum4" style="color: #606060">   4:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum5" style="color: #606060">   5:</span>     db.SubmitChanges();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum6" style="color: #606060">   6:</span> }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum7" style="color: #606060">   7:</span> <span style="color: #0000ff">catch</span> (ChangeConflictException e)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum8" style="color: #606060">   8:</span> {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum9" style="color: #606060">   9:</span>     Console.WriteLine(e.Message);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum10" style="color: #606060">  10:</span>     <span style="color: #008000">// Make some adjustments.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #008000">// ...</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum12" style="color: #606060">  12:</span>     <span style="color: #008000">// Try again.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum13" style="color: #606060">  13:</span>     db.SubmitChanges();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; color: black; direction: ltr; line-height: 12pt; font-family: 'Courier New',courier,monospace; background-color: #f4f4f4; text-align: left;"><span id="lnum14" style="color: #606060">  14:</span> }</pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.myverbaloutlet.net/2009/09/linq-to-sql-datacontext-and-transactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
