0

I'm a complete newbie to LINQ, so please bare with my stupid questions.

Using Visual Studio I've created a DBML file, and added a table to it from a local database. This created a data context called UserDataContext. In my ASPX page I can create an instance of the data context using:

UserDataContext db1 = new UserDataContext(); 

However when I try to query against the table I get to:

var query = from o in db1. 

and from there I can't see the table.... the dbml shows the table has public access.

Any ideas what I've missed?

4
  • var query = from o in db1 // this will not compile. you forgot "select" part Commented Jul 18, 2010 at 13:29
  • 1
    If you post code or XML, please highlight those lines in the text editor and click on the "code" button (101 010) on the editor toolbar to nicely format and syntax highlight it! Commented Jul 18, 2010 at 13:43
  • Did you ever compile the project before trying to write the Linq-to-SQL query? In order for intellisense etc. to work, I believe you need to at least compile/build your project once Commented Jul 18, 2010 at 13:44
  • 1
    Would it be reasonable to assume you're waiting for the intellisense to kick in and that's what you're not seeing? Commented Jul 18, 2010 at 15:28

6 Answers 6

1

You need to select it afterwards, so with var query = from o in db1 would be

var query = from o in db1 select o 
Sign up to request clarification or add additional context in comments.

1 Comment

Don't know why this got upvoted since it's both wrong and not relevant to the question.
1

Do you have using System.Linq; at the top of your code file? If you don't intellisense won't pick up for LINQ.

Comments

0
UserDataContext db1 = new UserDataContext(); var query = from o in db1 where o.fieldName = "abc" select p; 

1 Comment

@godz: to format your question, select it in the editor and press Control-K.
0

I think he's asking more of why he can't see the table in the query

Have you built your solution since you created the Linq to SQL Models, if you haven't done this they won't show up.

Comments

0

Ensure your class is in the same namespace as your .dbml file. If your .dbml is in a subdirectory, it'll inherit that subdirectory as part of the namespace of the .dbml.

Comments

0

If you want to query all tables in the database, or all columns in a table, I think you'll find this article useful.

Also, as zerkms pointed out in a comment, a LINQ query requires a select statement. It might help if you check out the desugared form of the LINQ query - it certainly helped me in avoiding these kinds of mistakes.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.