<?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>I Learnt Today... &#187; VB.Net</title>
	<atom:link href="http://www.ilearnttoday.com/category/vbnet/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ilearnttoday.com</link>
	<description>This is where I share what I learn day by day...</description>
	<lastBuildDate>Tue, 17 Jan 2012 12:44:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>D LINQ : How to Map Columns Which Auto Generate Values At the Database</title>
		<link>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database</link>
		<comments>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database#comments</comments>
		<pubDate>Mon, 11 May 2009 17:37:17 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET exception]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[auto-generate]]></category>
		<category><![CDATA[Cannot insert explicit value for identity column in table 'tbl_Process' when IDENTITY_INSERT is set to OFF]]></category>
		<category><![CDATA[DLINQ]]></category>
		<category><![CDATA[IDENTITY_INSERT]]></category>
		<category><![CDATA[IsDbGenerated]]></category>
		<category><![CDATA[IsDbGenerated:=True]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[primary key]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server exception]]></category>
		<category><![CDATA[Windows Application]]></category>

		<guid isPermaLink="false">http://www.ilearnttoday.com/?p=390</guid>
		<description><![CDATA[2009-05-11 I have being working on a software application made on .Net and recently my client asked me to use<a href="http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><!--[endif]--><span style="color: silver;">2009-05-11</span></p>
<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-5478118713208336";
/* LeadIn */
google_ad_slot = "2638602320";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p style="text-align: justify;">I have being working on a software application made on .Net and recently my client asked me to use D LINQ instead of SQL.</p>
<p style="text-align: justify;">D LINQ has great benefits loaded! As I started working with DLINQ I started to know that preventing SQL injection is not a headache anymore and misspelled SQL queries will not trouble agian at run time because DLINQ generates all necessary SQL inside the framework!</p>
<p style="text-align: justify;">I chose to use annotations inside the class instead of using separate xml file. Following is a part of the first class I ported to D LINQ.</p>
<p style="text-align: justify;">
<pre class="brush: vb; title: ; notranslate">&lt;/p&gt;
_
Public Class Process
_
Public ProcessID As Integer
_
Public BusinessProcessID As String
_
Public ProcessText As String
...
...
</pre>
<p style="text-align: justify;">ProcessID column is the primary key of my database table tbl_Process.</p>
<p style="text-align: justify;">Important Point: I use database to auto-generate values for the primary key column (integer value incremented by one).</p>
<p style="text-align: justify;">So when I run the application, It gave me this unexpected error:</p>
<p style="text-align: justify;"><strong><em>Cannot insert explicit value for identity column in table &#8216;tbl_Process&#8217; when IDENTITY_INSERT is set to OFF.</em></strong></p>
<p style="text-align: justify;">Basically, the <strong><em>IDENTITY_INSERT</em></strong> when using the database to auto generate value for a field but when I ran a SQL insert statement at the database end it worked fine!</p>
<p style="text-align: justify;">After some tough time I found out the solution for this problem!</p>
<p style="text-align: justify;">When we use an auto-generate field in a data table we have to specifically mention it in the matching field in the appropriate class.</p>
<p style="text-align: justify;">The code to state this is:</p>
<p style="text-align: justify;"><em>Syntax:</em></p>
<p style="text-align: justify;"><strong><em>IsDbGenerated:=True</em></strong></p>
<p style="text-align: justify;">This has to be added to the annotation added for the specific column like:</p>
<p style="text-align: justify;">
<pre class="brush: vb; title: ; notranslate">&lt;/p&gt;
_
Public ProcessID As Integer
</pre>
<p style="text-align: justify;">Now D LINQ can understand that the field value is auto-generated by the database!</p>
<p style="text-align: justify;"><span style="color: green;">Was this post helpful to you? How can I improve? &#8211; Your comment is highly appreciated!</span></p>
<p style="text-align: justify;"><span style="color: silver;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

