Friday, August 12, 2011

LINQ to SQL not working on SharePoint 2010

I recently created a user control that was hosted on a SharePoint 2010 server using the Smart Part. This user control contained a simple LINQ to SQL statement that looked like this:

int count = (from address in db.JobsDistribution
                 where address.Active == true
                 select address).Count();

I was getting a compile error: Missing ; on line xx.

It turned that the default compiler used by the SharePoint 2010 web application was .NET Framework 2.0. This issue was fixed by adding the following section in the web.config file of the application within the <configuration> section:


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


No comments:

Post a Comment