Linq to Sql support templates for v2.5 are now available in the customer area. We'll release them to the public site in a couple of weeks if no more bugs are found
To download: go to the customer area -> 2.5 section -> tasks and templates
Linq to SQL templates and templatebindings
Released on: 23-apr-2008
For LLBLGen Pro version: v2.5
Created by: Solutions Design, http://www.llblgen.com
Target language: C#
Purpose
These templates allow you to generate code for Linq to Sql using any LLBLGen Pro project. You can use the LLBLGen Pro's designer to create and maintain a project and generate code directly from the designer using these templates. This allows you to use the powerful catalog refreshing capabilities as well as the other features of the LLBLGen Pro designer.
Linq to Sql's code generator isn't template based nor does it split up the classes in one class-per-file. These templates allow you to alter the generated code and also give you one class per file.
Installation
Unpack the archive in the LLBLGen Pro installation folder. It will tell you that there's already a folder called 'Tasks' and a folder called 'Templates'. Click 'Yes' when you're asked to overwrite these folder declarations: doing so will keep the current folders and will add the archive's contents to these folders.
You can also unpack the Tasks folder in the archive to another folder where you keep your additional tasks files, as long as it's a folder reachable when you want to generate code inside LLBLGen Pro.
Requirements
LLBLGen Pro v2.5 of January 1st or later. Linq to Sql only works on SqlServer, so using these templates on a project other than a SqlServer project won't work.
Compatibility and caveats
Linq to Sql doesn't support m:n relations nor inheritance with hierarchy type TargetPerEntity. It also doesn't support abstract inheritance hierarchy roots. Linq to Sql also doesn't support .NET UDT typed fields. Linq to Sql doesn't have the concept of a TypedList, so these are ignored.
The templates will work around these limitations by either ignoring the information (as with the inheritance hierarchies) or try to make it work (ignore 'abstract' on root types)
LLBLGen Pro's designer currently doesn't allow you to specify stored procedure calls as persistence methods, so you can't use a stored procedure for insert/update/delete of an entity.
Linq to Sql's designer uses a trick to obtain the resultset type of a stored procedure: SET FMTONLY ON;exec proc;SET FMTONLY OFF. The downside of this is that with procs which use temptables or have multiple resultsets, it can go wrong. LLBLGen Pro therefore dropped this feature some years ago and therefore it doesn't have any type information about the resultset. It therefore is currently not possible to generate stored procedure calls into the Linq to Sql code with proper type information as this meta-data isn't available.
Usage
- Create or open a SqlServer based LLBLGen Pro project and press F7 or select Project -> Generate
- Under 'Template group' select 'Linq to Sql'
- Under 'Target platform' select '.NET 3.5'
- Specify a root namespace and a destination folder. Use a separate folder from your main solution
for the generated code as these templates generate a separate project.
- At tab 3, you now have a preset available to you which contains the tasks.
- Click Start generator.
You'll get a complete VS.NET 2008 class library generated. It contains a folder, 'EntityClasses' which contains per entity type a class file. Also generated are a Mappings.dbml file which contains the mapping information and a DataContext.cs file which contains the datacontext class.
To use it in your own solution, you've to make sure that your application's config file contains a connection string element for the ConnectionStrings section. You should copy the connection string from the generated app.config file to your application's config file and give the connection string the same name as the element in the generated app.config file, e.g. 'Main.ConnectionString'. After that, reference the generated VS.NET 2008 project and you're
set to use the generated code!
Support
These templates are an official release, so if you have questions, remarks, bugreports etc., please post a message in one of the forums at http://www.llblgen.com/tinyforum
FAQ
Q: Is this the end of your own o/r mapper framework?
A: No, not at all. We will keep on supporting our own framework as we think it's the best o/r mapper framework out there. We just wrote these templates to allow users of another o/r mapper framework, Linq to Sql, to use our designer's power as Linq to Sql's designer lacks model refreshing support.
Q: Do you plan to create more templates like these in the future?
A: We indeed have plans to release more templates for other frameworks, also with more advanced features than these initial templates.