Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda Expression of Select * from TableName

Tags:

c#

linq

c#-3.0

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.

like image 562
Wondering Avatar asked Jul 15 '09 13:07

Wondering


People also ask

How do you write a select query in lambda expression?

select (s => new SelectListItem { Value = s. ID. ToString(), Text = s.Name} ); select (s => new SelectListItem { Value = s.ID + "", Text = s.Name} );

What is lambda expression in SQL?

A lambda expression is a short block of code which takes in parameters and returns a value. Lambda expressions are similar to methods, but they do not need a name and they can be implemented right in the body of a method.


2 Answers

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);
like image 152
Garry Shutler Avatar answered Sep 19 '22 16:09

Garry Shutler


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...

like image 40
Richard Berg Avatar answered Sep 21 '22 16:09

Richard Berg