Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinqDataSource DataContext Object Not Showing In Configure Data Source

I added a LinqToSQL Class to my project and put it in my App_code folder.

I then added a LinqDataSource to a new web page and tried to configure it to use this class, but it does not show up as an option in the DataContext drop down.

I moved the class to the root directory of my project and it is now available in the DataContext drop down box.

I created a new project with 1 page and tried it again and still the same thing. If the class isn't in my root directory it isn't available.

I have searched the internet and everything I have found indicates that the class should be in my App_code folder, but it doesn't work if I put it there.

Does anyone know why the class isn't available if I put it in the App_code folder.

Thank You

like image 503
Tracy Avatar asked Nov 05 '22 07:11

Tracy


2 Answers

I created a new local installation of my website and then opened it in VS 2010, and this time it saw the Data Context. It means you have to debug your project first, then you will see the Data Context.

like image 45
Anne Avatar answered Nov 14 '22 21:11

Anne


  1. Open your .dbml file in VS2010 and make sure that it only has the tables in it that are related to what you are doing with the .dbml file. I opened my to discover I had taken 3 tables when all I needed was one.
  2. After you have done this, in solution explorer find your .dbml file, and expand it.
  3. There should be two files inside the expansion:
    • <name-of-your-dbml-file>.dbml.layout, and
    • <name-of-your-dbml-file>.designer.cs
  4. Double-click <name-of-your-dbml-file>.designer.cs to open it.
  5. Take note of the namespace in this file.
  6. Open the code-behind page of the web page (.aspx or .ascx file).
  7. Click Source, and add using <the-name-space-from-step-four>
    1. Go back to the web page's (not the code-behind) Design view.
  8. Click your LinqDataSource
  9. Click the little arrow to reveal the LINQDataSource Tasks, and click Configure Data Source...
    1. Be sure that Show only DataContext objects is unchecked.
    2. From the Choose your context object: dropdown look for the namespace we noted in step 4.

From there you should be able to select your DataContext class and click next.

like image 164
leeand00 Avatar answered Nov 14 '22 23:11

leeand00