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.
Updates
- 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
In action!
Screen cast is no longer available, sorry.
CodePlex
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.
Enjoy!
[)amien
17 responses
[...] LINQ to SQL Templates Updated, Now on CodePlex (Damien Guard) [...]
[...] A newer version of this LINQ to SQL template is available. [...]
[...] A newer version of this LINQ to SQL template is available. [...]
viewing plug-in with moonlight for linux. works well.
[...] Pour ceux que ça intéresse voici le lien : http://damieng.com/blog/2009/01/19/linq-to-sql-templates-updated-now-on-codeplex [...]
Brilliant!
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)?
Regards,
Melle
@Melle you’ll need to install either the Clarius or the Tangible T4 editors as there is no syntax highlighting in-the-box.
[)amien
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” “VOC3_DB.tt” 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.
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.
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: 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)
[)amien
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.
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
@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.
[)amien
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
Hi,
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)
[...] Guard has put together some T4-templates (read more) that could be used to take control of how the DataContext and the entities are generated. All I [...]