Search code examples
asp.netlinq-to-sql.net-3.5namespacesapp-code

Linq-to-SQL datacontext not generating an object


I am working in a .NET 2.0, recently upgraded to .NET 3.5 environment (VS2008, VB.NET) on an existing ASP.NET website project. I am able to generate a Linq-to-SQL Class (also called a DataContext?) in the App Code folder, drag over tables from an active connection, and save it. Let's call it MyDB. When I go to the code-behind file for my page and try to declare an object of "MyDBDataContext" it is not in the intellisense, indicating that it is not accessible. I checked the references, and that has to be set correctly because I made the .dbml file. I made a new test windows app project and it behaved exactly as expected, and I could follow this blog without a problem.

Is there something inherent to web projects that doesn't allow for these auto-generated objects to be usable? Is App Code the right place to declare it?

If you can't tell from the above, I am new to the industry and really new to LINQ.

thanks for your help.


Solution

  • Try expanding the dbml file and open the designer.cs file underneath, and make sure the DataContext class is in the same namespace as the codebehind class. If not, either change the namespace or include it with a using Namespace statement the top.