<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: LINQ to SQL template for Visual Studio 2008</title>
	<atom:link href="http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008/feed" rel="self" type="application/rss+xml" />
	<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008</link>
	<description>A .NET developer in Redmond</description>
	<lastBuildDate>Sun, 14 Mar 2010 14:22:22 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Fabricio</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-14672</link>
		<dc:creator>Fabricio</dc:creator>
		<pubDate>Tue, 14 Apr 2009 02:34:52 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-14672</guid>
		<description>Hi Damien,

First of all, you&#039;ve done a great job!

I&#039;ve just found an issue with a specific scenario that is causing your template to generate an invalid code. It seems that OOTB dbml code generator has an workaround to circumvent this issue.

If you have a primary key of type uniqueidentifier, and define a default constraint of (new_id()) for it, when you drag the table from database explorer into dbml file, the AutoSync settings for the column will remain as &quot;.Never&quot; even if the DbAutoGenerated property is true. But, in the .designer.cs file, the column will not receive the AutoSync=AutoSync.Never attribute value.
By using your template, the attribute value above will be included, and the following error will be displayed when you try to load data into DataContext with the offending configuration:
&quot;Incorrect AutoSync specification for member &#039;PKColumnName&#039;&quot;.

I&#039;ve just changed the line 258 of your TT script as the following:
if (column.AutoSync != AutoSync.Default &amp;&amp; column.Type != typeof(System.Guid)) {#&gt;, AutoSync=AutoSync.&lt;#}

this way, if the column has an AutoSync set, it will only generate the code if the column type isn&#039;t Guid.

I hope my change will solve the problem, and I hope it is right.
Please, let me know if I did anything stupid here. :)

Regards,
Fabrício</description>
		<content:encoded><![CDATA[<p>Hi Damien,</p>
<p>First of all, you&#8217;ve done a great job!</p>
<p>I&#8217;ve just found an issue with a specific scenario that is causing your template to generate an invalid code. It seems that OOTB dbml code generator has an workaround to circumvent this issue.</p>
<p>If you have a primary key of type uniqueidentifier, and define a default constraint of (new_id()) for it, when you drag the table from database explorer into dbml file, the AutoSync settings for the column will remain as &#8220;.Never&#8221; even if the DbAutoGenerated property is true. But, in the .designer.cs file, the column will not receive the AutoSync=AutoSync.Never attribute value.<br />
By using your template, the attribute value above will be included, and the following error will be displayed when you try to load data into DataContext with the offending configuration:<br />
&#8220;Incorrect AutoSync specification for member &#8216;PKColumnName&#8217;&#8221;.</p>
<p>I&#8217;ve just changed the line 258 of your TT script as the following:<br />
if (column.AutoSync != AutoSync.Default &amp;&amp; column.Type != typeof(System.Guid)) {#&gt;, AutoSync=AutoSync.&lt;#}</p>
<p>this way, if the column has an AutoSync set, it will only generate the code if the column type isn&#8217;t Guid.</p>
<p>I hope my change will solve the problem, and I hope it is right.<br />
Please, let me know if I did anything stupid here. :)</p>
<p>Regards,<br />
Fabrício</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BryceH</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-13219</link>
		<dc:creator>BryceH</dc:creator>
		<pubDate>Tue, 31 Mar 2009 18:15:18 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-13219</guid>
		<description>First of all, I just wanted to say that this is great stuff. Thanks Damien!!!

Secondly...
I ran into an issue when generating separate class files. Since each class file was rebuilt no matter if there was truly a change my source control would always see them as modified files due to the timestamp on the file. So, I added some code to the L2ST4.ttinclude file, ManagementStrategy class, CreateFile method. The new code is below.

&lt;pre&gt;&lt;code&gt;&lt;code&gt;internal virtual void CreateFile(String fileName, String content) 
{
     if (File.Exists(fileName))
     {		
	//get the date saved to the new version 
        //note: 32 is the length of the Generated at comment plus the datetime info
	string newDate = content.Substring(content.IndexOf(&quot;Generated at&quot;), 32);	//get the text of the existing file
	string existingText = File.ReadAllText(fileName);
	//get the date in the existing file
	string textToReplace = existingText.Substring(
             existingText.IndexOf(&quot;Generated at&quot;), 32);
	//replace the date in the existing file with the new date
	existingText = existingText.Replace(textToReplace, newDate);
	//compare contents to determine if save is necessary
	if (existingText != content)
	{
		File.WriteAllText(fileName, content);	
	}
     }	
     else
     {
	 File.WriteAllText(fileName, content);
     }	
}&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>First of all, I just wanted to say that this is great stuff. Thanks Damien!!!</p>
<p>Secondly&#8230;<br />
I ran into an issue when generating separate class files. Since each class file was rebuilt no matter if there was truly a change my source control would always see them as modified files due to the timestamp on the file. So, I added some code to the L2ST4.ttinclude file, ManagementStrategy class, CreateFile method. The new code is below.</p>
<pre><code></code><code>internal virtual void CreateFile(String fileName, String content)
{
     if (File.Exists(fileName))
     {
	//get the date saved to the new version
        //note: 32 is the length of the Generated at comment plus the datetime info
	string newDate = content.Substring(content.IndexOf("Generated at"), 32);	//get the text of the existing file
	string existingText = File.ReadAllText(fileName);
	//get the date in the existing file
	string textToReplace = existingText.Substring(
             existingText.IndexOf("Generated at"), 32);
	//replace the date in the existing file with the new date
	existingText = existingText.Replace(textToReplace, newDate);
	//compare contents to determine if save is necessary
	if (existingText != content)
	{
		File.WriteAllText(fileName, content);
	}
     }
     else
     {
	 File.WriteAllText(fileName, content);
     }
}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony and Zuzana&#8217;s World &#187; T4 POCO Templates for L2S and EF</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10860</link>
		<dc:creator>Tony and Zuzana&#8217;s World &#187; T4 POCO Templates for L2S and EF</dc:creator>
		<pubDate>Fri, 16 Jan 2009 13:11:30 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10860</guid>
		<description>[...] not find any T4 templates to generate POCOs from a database. However, I did find a template by Damien Guard that serves as a wholesale replacement for LINQ to SQL entities. Using this template as a starting [...]</description>
		<content:encoded><![CDATA[<p>[...] not find any T4 templates to generate POCOs from a database. However, I did find a template by Damien Guard that serves as a wholesale replacement for LINQ to SQL entities. Using this template as a starting [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10805</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 07 Jan 2009 17:31:01 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10805</guid>
		<description>Hi Damien,

Should this template support SQL functions? I am getting an error when executing a method that calls a function:

&#039;System.Boolean&#039; is not a valid return type for a mapped stored procedure method.

Comparing the template generated cs with the original O/R designer generated code it looks like I am missing the IsComposable attribute. How easy would it be to modify the template to support functions?

Thanks in advance for your help.

Regards,

Steve</description>
		<content:encoded><![CDATA[<p>Hi Damien,</p>
<p>Should this template support SQL functions? I am getting an error when executing a method that calls a function:</p>
<p>&#8216;System.Boolean&#8217; is not a valid return type for a mapped stored procedure method.</p>
<p>Comparing the template generated cs with the original O/R designer generated code it looks like I am missing the IsComposable attribute. How easy would it be to modify the template to support functions?</p>
<p>Thanks in advance for your help.</p>
<p>Regards,</p>
<p>Steve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10580</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Fri, 12 Dec 2008 13:20:54 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10580</guid>
		<description>Thanks again for the quick update!</description>
		<content:encoded><![CDATA[<p>Thanks again for the quick update!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10574</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 12 Dec 2008 10:55:09 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10574</guid>
		<description>The standard generation tool supports using an enum as the type of a database int field. A type load exception occurs if you try this with the template. This can be replicated by creating an enum and setting a fields type to that in the designer.

I will give it a go and post the result if I make it happen, but would like to know if it has been done already.

Thanks.</description>
		<content:encoded><![CDATA[<p>The standard generation tool supports using an enum as the type of a database int field. A type load exception occurs if you try this with the template. This can be replicated by creating an enum and setting a fields type to that in the designer.</p>
<p>I will give it a go and post the result if I make it happen, but would like to know if it has been done already.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10563</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Wed, 10 Dec 2008 19:19:47 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10563</guid>
		<description>Hi, thanks for including IsDelayLoaded. I got something else which seems to be a small bug. In EntitySet associations, the get accesor references a &quot;serializing&quot; variable which is never declared:

get {
  if (serializing &amp;&amp; !_DuplicatedPictures.HasLoadedOrAssignedValues) {
       return null;
...

As soon as I remove it the generated code compiles and seems to work fine. ;)</description>
		<content:encoded><![CDATA[<p>Hi, thanks for including IsDelayLoaded. I got something else which seems to be a small bug. In EntitySet associations, the get accesor references a &#8220;serializing&#8221; variable which is never declared:</p>
<p>get {<br />
  if (serializing &amp;&amp; !_DuplicatedPictures.HasLoadedOrAssignedValues) {<br />
       return null;<br />
&#8230;</p>
<p>As soon as I remove it the generated code compiles and seems to work fine. ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LINQ to SQL templates updated &#187; DamienG</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10534</link>
		<dc:creator>LINQ to SQL templates updated &#187; DamienG</dc:creator>
		<pubDate>Mon, 08 Dec 2008 07:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10534</guid>
		<description>[...] a quick post to let people know that I&#039;ve been continually updating my LINQ to SQL templates for Visual Studio&#039;s built-in templating language (T4) since they were published in [...]</description>
		<content:encoded><![CDATA[<p>[...] a quick post to let people know that I&#8217;ve been continually updating my LINQ to SQL templates for Visual Studio&#8217;s built-in templating language (T4) since they were published in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10528</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Sun, 07 Dec 2008 19:09:41 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10528</guid>
		<description>Hi, sir. Love your templates, thanks for publishing them :)

I made a few small changes to support the IsDelayLoaded attribute in the DBML file. All you need is to use Link instead of T for the column&#039;s private storage field, and use _storageField.Value instead of just _storageField in the getter and setter of the column&#039;s public property.

I also added a bool IsDelayLoaded property to your Column class in the ttinclude file and got the value from the XElement like you did for the other attributes. Voila!</description>
		<content:encoded><![CDATA[<p>Hi, sir. Love your templates, thanks for publishing them :)</p>
<p>I made a few small changes to support the IsDelayLoaded attribute in the DBML file. All you need is to use Link instead of T for the column&#8217;s private storage field, and use _storageField.Value instead of just _storageField in the getter and setter of the column&#8217;s public property.</p>
<p>I also added a bool IsDelayLoaded property to your Column class in the ttinclude file and got the value from the XElement like you did for the other attributes. Voila!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ferne</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10438</link>
		<dc:creator>Ferne</dc:creator>
		<pubDate>Thu, 27 Nov 2008 22:06:46 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10438</guid>
		<description>Wow!! It&#039;s getting better and better. Keep it up man.,</description>
		<content:encoded><![CDATA[<p>Wow!! It&#8217;s getting better and better. Keep it up man.,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-10298</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 17 Nov 2008 12:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-10298</guid>
		<description>Thank you for this work - this has resolved a lot of issues for me.

However, I have a class that is using InheritanceMapping and I notice that the Inheritance Default is not generated even though I have it set in the dbml, for example,

[Table(Name=@&quot;dbo.People&quot;)]
[DataContract(IsReference=true)]
[InheritanceMapping(Code=&quot;0&quot;, Type=typeof(Person),
                     IsDefault=true)] //isDefault=true is not being generated here
[InheritanceMapping(Code=&quot;1&quot;, Type=typeof(Engineer))]</description>
		<content:encoded><![CDATA[<p>Thank you for this work &#8211; this has resolved a lot of issues for me.</p>
<p>However, I have a class that is using InheritanceMapping and I notice that the Inheritance Default is not generated even though I have it set in the dbml, for example,</p>
<p>[Table(Name=@"dbo.People")]<br />
[DataContract(IsReference=true)]<br />
[InheritanceMapping(Code="0", Type=typeof(Person),<br />
                     IsDefault=true)] //isDefault=true is not being generated here<br />
[InheritanceMapping(Code="1", Type=typeof(Engineer))]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michaeln</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-9714</link>
		<dc:creator>michaeln</dc:creator>
		<pubDate>Fri, 17 Oct 2008 20:38:27 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-9714</guid>
		<description>liviu,

Are you going to make your assembly (to generate the dbml) available to download?</description>
		<content:encoded><![CDATA[<p>liviu,</p>
<p>Are you going to make your assembly (to generate the dbml) available to download?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Guard</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-9556</link>
		<dc:creator>Damien Guard</dc:creator>
		<pubDate>Mon, 29 Sep 2008 14:45:50 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-9556</guid>
		<description>Is this the encoding issue or something else?

[)amien</description>
		<content:encoded><![CDATA[<p>Is this the encoding issue or something else?</p>
<p>[)amien</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liviu</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-9555</link>
		<dc:creator>liviu</dc:creator>
		<pubDate>Mon, 29 Sep 2008 07:36:37 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-9555</guid>
		<description>Sidar, thank you for the links. I will take a look.

Damien, the template unfortunately still doesn&#039;t work  100% compatible with the built in generator. I have that dbml that crashes the template but does produce correct output otherwise. I had to use SQlMetal for now .. :-(</description>
		<content:encoded><![CDATA[<p>Sidar, thank you for the links. I will take a look.</p>
<p>Damien, the template unfortunately still doesn&#8217;t work  100% compatible with the built in generator. I have that dbml that crashes the template but does produce correct output otherwise. I had to use SQlMetal for now .. :-(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay</title>
		<link>http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008#comment-9522</link>
		<dc:creator>Jay</dc:creator>
		<pubDate>Wed, 24 Sep 2008 19:49:30 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/?p=1008#comment-9522</guid>
		<description>Damien - thanks for today&#039;s update to the template. It resolved the issue I was having and worked perfectly to produce the generated LINQ-To-SQL types.</description>
		<content:encoded><![CDATA[<p>Damien &#8211; thanks for today&#8217;s update to the template. It resolved the issue I was having and worked perfectly to produce the generated LINQ-To-SQL types.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
