I have a Visual Studio 2012 web application (fw. 4.5) where I am trying to execute linq in my sql database. I added a datacontext to my project and put it in the root folder. In the datacontext file, I added a table named GlobalMenu from my SQL 2012 express database.
I am trying to access data using linq using the following command:
DataContextDataContext db = new DataContextDataContext(); var menupages = from p in db.GlobalMenus select p;
Intellisense Reports:
Module 'System.Data.Linq' Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089' should be referenced
When I compile and try to run my application, I get:
CS0012: The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
System.Data.Linq 4.0.0.0 completed in my project and I added manually
<dependentAssembly> <assemblyIdentity name="System.Data.Linq" publicKeyToken="b77a5c561934e089"/> <bindingRedirect oldVersion="1.0.0.0-4.5.0.0" newVersion="4.0.0.0"/> </dependentAssembly>
in the runtime section of web.config. However, the error still exists.
Another problem is that when I put the DataContext file in the App_Code folder, I get another error.
Intellisense reports: Cannot resolve select symbol
After compiling and running the web application, I get a runtime error inside the datacontext file in the constructor file.
using System.Data.Linq; using System.Data.Linq.Mapping;
Cannot resolve the "Linq" character.
This web project is based on the standard "ASP.NET Web Form Application" and I'm trying to abandon the basic programming, so I don’t see what I'm doing wrong here.