LINQ to SQL templates updated, now on CodePlex

My templates that allow you to customize the LINQ to SQL code-generation process (normally performed by SQLMetal/LINQ to SQL classes designer) have been updated once again.


  • Now licensed under the Microsoft Public License and hosted at CodePlex
  • User options specified with a var options block at the start of the template
  • Option for each class to be a separate file that is reflected in the VS project EntityPerFile=true
  • Detection and support of IsComposable functions
  • General code clean-up and better error handling such as missing DBML file


CodePlex makes it easier for people to be able to see and merge updates in with their own modified versions as well as report issues via the issue tracker etc. There is also an RSS feed that lets you keep track of releases, source updates or whatever else you are interested in.

For now it is a grab-the-source style release but I hope to publish downloadable tested releases wrapped up in a Visual Studio Installer (VSI) package to make getting started easier soon.  Feel free to grab the sources directly via TFS/Subversion to be able to diff them with your own modified versions.



12 responses

  1. Avatar for matt

    viewing plug-in with moonlight for linux. works well.

    matt January 25, 2009
  2. Avatar for Melle


    I will make it to work on separate assemblies. One for the entities and one for the data access. This looks really great. Thanks for the effort!!

    How do you get the syntaxt highlighting on the .TT source (without VS complaining about whitespace and identifiers - I set it as a C# file)?



    Melle June 19, 2009
  3. Avatar for Damien Guard

    @Melle you'll need to install either the Clarius or the Tangible T4 editors as there is no syntax highlighting in-the-box.

    Damien Guard June 19, 2009
  4. Avatar for Ken_S.

    When I try it I get...

    System.Runtime.Serialization.InvalidDataContractException: Type 'System.Runtime.Serialization.DataContractSerializer' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
    at VOC3_Web_Services.VOC3_Web_Services.getTitle(String _user, String _criterion) in C:\\Download\\C#_Projects\\VOC3_Web_Services\\VOC3_Web_Services\\VOC3_Web_Services.asmx.cs:line 123

    Also, how do I remove it? I took out the "L2ST4.ttinclude" "" files but now get the following Warning...

    The custom tool 'MSLinqToSQLGenerator' failed while processing the file 'Data_Layer\VOC3_DB.dbml'.

    Thank you.

    Ken_S. July 8, 2009
  5. Avatar for Jordan Rieger

    This is a fantastic piece of plumbing and will save my team a lot of work, specifically in the realm of serialization. I really appreciate your efforts, Damien. I really hope DataContract serialization support is native in the next version of Visual Studio LINQ to SQL.

    Jordan Rieger October 6, 2009
  6. Avatar for Nigel Deakin

    Love the reorganised code but not so taken by the CA warnings I get from the code that gets generated.

    How do I surpress any code warnings from the generated code. The project is marked to ignore such but both standard VS2008 and running with this template causes CA to shout out warnings.

    Regards, Nigel

    Nigel Deakin November 3, 2009
  7. Avatar for Damien Guard

    @Nigel: The warnings I see are:

    1. Naming - casing/underscores/discrete (change the names in the DBML)
    2. Usage - Settable collection properties (would be a breaking change but you could suppress this warning by modifying the template)
    Damien Guard November 3, 2009
  8. Avatar for Pavel Kubik

    Hi, what if I have columns like 'private' and 'operator' in my database table. Compiling the code generated with this template fails, obviously. I can't (or lets say don't want to) make any changes to my tables... Any ideas?

    Thanks, Pavel.

    Pavel Kubik November 10, 2009
  9. Avatar for Daniel Cotter

    Great tool! It's really nice to be able to customize the L2S code like that. I used it to fix a circular reference problem LINQ was having when serializing a parent entity to JSON (by adding [ScriptIgnore] above any Associations).

    On another note, the line base(global::.Default., mappingSource) was causing a build error for me (couldn't find Default). Is this just because I'm using VS2010b2?


    Daniel Cotter November 11, 2009
  10. Avatar for Damien Guard

    @Daniel : This is normally caused by a DBML coming from another project. The DBML tends to reference the connection via the app.config but the app.config wasn't copied. Opening the DBML in the designer will detect this and remove the offending code so you can setup a new connection.

    Damien Guard November 11, 2009
  11. Avatar for Harro Schmidt

    Hi Damien,

    When using the built-in generator the namespace of my DataContext is MyCompany.Database (the .dbml is located in the folder 'Database' within the project). But with using the template, the namespace 'Database' is missing. Any ideas?


    Harro Schmidt December 23, 2009
  12. Avatar for KLCA


    Excuse me sir ... where is the .wmv file? I'm trying to build an MetaData file automatically having as a start point my .dbml LINQ to SQL DataContext File.

    Carlos Porras (El Salvador)

    KLCA February 19, 2010