LINQ to SQL templates for T4-Adding Interfaces for C#

6. October 2009

I was working in these templates and wanted to add interfaces.  

I found a link in the discussions here, from Jwooley stating he had done this: http://www.thinqlinq.com/Post.aspx/Title/Generating-Interfaces-for-LINQ-to-SQL-Entities

Well he did it, but in Visual basic and I needed C#, so I changed up the script.   I tried to add this script to his site, but the submission didnt allow it so I will post it here and add a link to his site.

Hope this saves someone a little time:

(Follow the instructions on the think link site and replace this part :

namespace <#=data.EntityNamespace#>	
{
<#		}
#><#if (options.CreateInterfaces) { #>
	/// <summary>
    /// <#=class1.Name#> interface
    /// </summary>
	<#=code.Format(class1.TypeAttributes)#>interface I<#=class1.Name#>
	{
	<#			foreach(Column column in class1.Columns) {#>
	<# if (column.IsReadOnly) {#>ReadOnly <#}#> <#=code.Format(column.Type)#> <#=column.Member#>{ get; set; }
	<# } 
	#>
	}
<# } 
#>
<#		if (data.Serialization && class1.IsSerializable) {

.Net , C#, Programming

Comments

10/7/2009 3:24:48 PM #
Thanks for taking the effort to do the C# translation. I often find I learn more when I code it myself as compared to just consuming what someone else wrote. It just goes to show that doing this in T4 is really pretty easy.
10/12/2009 7:51:43 AM #
Jim, thank you for doing all the work on the visual basic side.  It was quite easy to modify what you had already done.  Agreed, it does help when you jump in and do it yourself.      

I will be doing more with T4 in the future.  I keep finding new possibilities with T4.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading