views:

137

answers:

6

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?

A: 

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.

ShdNx
A: 
UserDataContext db1 = new UserDataContext();
var query = from o in db1
            where o.fieldName = "abc"
            select p;
@godz: to format your question, select it in the editor and press Control-K.
John Saunders
@John Saunders thanks.
+1  A: 

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

var query = from o in db1
select o
Spooks
Don't know why this got upvoted since it's both wrong and not relevant to the question.
fearofawhackplanet
A: 

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

Greg Kurts
A: 

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.

msarchet
A: 

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.

p.campbell