Google Android Development Agency SASS
Showing posts with label linq. Show all posts
Showing posts with label linq. Show all posts

Friday, 22 January 2010

Using C# 3.0 and LINQ with Kentico

I just encountered a weird problem with a custom webpart in Kentico CMS v4.

Our project is configured in VS.NET as a .NET 3.5 website; web.config references 3.5.0 assemblies and there's plenty of references to System.Linq in classes.

This morning I cane across an instance where I thought it might be useful to use a LINQ query to extract a filtered List from another List. I wrote my code

var filtered = (from m in data where m.DepartmentID = 1 select m)

VS.NET syntax highlighting was happy and showed no errors. However, when I browsed to the website I got the error "the type or namespace name 'var' could not be found" and varyingly various different "missing )" errors.

Clearly IIS wasn't treating this website as a 3.5 site. Easy to fix thankfully, I just added the following to web.config:


<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
>
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>