Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3333034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:45:07+00:00 2026-05-17T23:45:07+00:00

I can successfully connect to the database with my datacontext object. I am able

  • 0

I can successfully connect to the database with my datacontext object. I am able to read and write to the database successfully, however I can’t use the same syntax that others appear to be using.

For example, when I want data from a table, I have to do something like this:

db = new UserDataDataContext(WebConfigurationManager.ConnectionStrings["UserData"].ConnectionString);
IQueryable Users = db.GetTable<User>();

I’d like to be able to write linq queries like how I see others doing them:

db = new UserDataDataContext(WebConfigurationManager.ConnectionStrings["UserData"].ConnectionString);
var query = from u in db.User
            where u.UserName == "Test"
            select u;

But intellisense does not recognize User as an property of db, and thus won’t compile. Intellisense doesn’t show any properties that look related to tables or entities of my database.

Here is the error message I am getting:

'System.Data.Linq.DataContext' does not contain a definition for 'User' and no extension method 'User' accepting a first argument of type 'System.Data.Linq.DataContext' could be found (are you missing a using directive or an assembly reference?)

Here is a rundown of what I am doing:

I used the database designer, dragged the tables in that I wanted.

Then I saved it as a dbml file.

It then created the new class that extends dataContext for me, named UserDataDataContext. I then instantiate a new instance of UserDataDataContext named db, passing in my connection string from Web.config.

Then I try to write a linq query referencing table names as properties of the db object, but it does not recognize them.

I can’t seem to find what I am doing wrong compared to all of the examples I’ve read. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:45:08+00:00Added an answer on May 17, 2026 at 11:45 pm

    I’m sure you have the following variable declaration somewhere:

    // variable is of type System.Data.Linq.DataContext
    DataContext db;
    

    Change it to:

    // variable is now of the appropriate subclass's type
    UserDataDataContext db;
    

    If db is a local variable and you can afford to inline the initialization and declaration together, it would be even better to use implicit typing instead:

    // db is implicitly of type UserDataDataContext
    var db = new UserDataDataContext(WebConfigurationManager.ConnectionStrings["UserData"].ConnectionString);
    

    C# is a safe and statically typed language. Although the object referred to by your reference will indeed, at run-time, have the properties you are expecting, the compiler won’t let this compile because these properties don’t exist on the variable‘s type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can successfully connect to MySQL from a DOS prompt, but when I try
I have problems using Mysql with MySQL Connector, I can successfully connect to a
I can successfully include main jquery files in /Scripts, but if my custom test.js
Having integrated merb_auth_password_slice as per the README, I can successfully login as redirect_after_login is
Title says what i'm trying to do. I can successfully generate an assembly if
I have an HBITMAP containing alpha channel data. I can successfully render this using
Can iPhone applications compiled against 2.1 be successfully installed via iTunes on a 2.0
How can I set a parameter of a sub-report? I have successfully hooked myself
Can somebody point me to a resource that explains how to go about having
I currently support an MS Access database that has linked connections using the Microsoft

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.