I am using T4 to generate some screens and middle-tier code for a project, and would like to use Linq to simplify some of my template code. However, when I try to use Linq, the template reports a syntax error.
LINQ that stands for Language Integrated Query (pronounced as “link”) is a . NET language extension that supports data retrieval from different data sources like XML document, databases and collections. It was introduced in the . NET 3.5 framework.
Yes. Right click on your project, select 'Options'->'Runtime' and select '2.0' from the drop-down list.
By default in Visual Studio 2008 (and as used in most online examples) the template is compiled with the 2.0 Framework, which does not include Linq. (See MSDN forum thread)
To solve the problem, three steps are needed:
Your template will now look something like this:
<#@ template language="C#v3.5" #> <#@ assembly name="System.Core" #> <#@ import namespace="System.Linq" #>
You can now use Linq and other new language features in your template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With