tags:

views:

469

answers:

3

Hi All,

I just want to know what's the lambda expression of Select * from TableName. Like in plain LINQ it will be var res=from s in db.StudentDatas select s; here StudentData is name of the table.

Thanks.

+1  A: 

You don't require a lambda expression. You just want all members of the collection.

yieldvs
+3  A: 

The compiler will translate it to something along these lines:

db.StudentDatas.Select(s => s)

The translation to SQL is done by the Base Class Library. SQL, of course, does not use lambda expressions...

Richard Berg
+2  A: 

The lambda expression isn't needed:

var res = db.StudentDatas;

You could use one but it would be rather pointless:

var res = db.StudentDatas.Select(s => s);
Garry Shutler
It's not needed from a logical perspective, but if the compiler optimized out the Select() call then there would be no opportunity for LINQ to SQL to invoke the database query.
Richard Berg
I will not use, but just wanted to know.Thanks for the expression.
Wondering
@Richard I'm not sure what you're saying. The compiler wouldn't optimise out code that you need to run.
Garry Shutler
@Gary I interpreted Wondering's question as "what happens behind the scenes," not "what's the best way to do this." What happens behind the scenes is that the 'select' keyword becomes a static method call on an IQueryable, whose argument is the lambda both of us gave in our answers.
Richard Berg