TableName中Select *的Lambda表达式

时间:2021-03-11 19:06:14

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.

我只想知道TableName中Select *的lambda表达式是什么。就像在普通的LINQ中一样,它将在db.StudentDatas中选择s的var res = from s;这里StudentData是表的名称。

Thanks.

5 个解决方案

#1


The lambda expression isn't needed:

不需要lambda表达式:

var res = db.StudentDatas;

You could use one but it would be rather pointless:

你可以使用一个,但它会毫无意义:

var res = db.StudentDatas.Select(s => s);

#2


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

SQL的转换由基类库完成。当然,SQL不使用lambda表达式......

#3


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

您不需要lambda表达式。你只想要集合的所有成员。

#4


While both are technically correct, as in they would both give the same result in its simplistic form, this is only because the default behavior of db.table is “Select”. Behind the scenes, they are different. While one is a System.Data.Linq.Table, the other is System.Linq.IQuerable. For example

虽然两者在技术上都是正确的,因为它们都会以简单的形式给出相同的结果,但这只是因为db.table的默认行为是“选择”。在幕后,他们是不同的。虽然一个是System.Data.Linq.Table,另一个是System.Linq.IQuerable。例如

var x = db.table ; var y= db.table(s=>s); 
X = y; 

would result in a compiler error.

会导致编译器错误。

When using the Dynamic Linq library, in cases where you have to create dynamic queries at runtime, you have to use an IQuerable as your initial select. Which means var qry = db.table(s=>s); as opposed to var qry = db.table; Then you can go on and chain your queries like: qry = qry.Where(bla bla bla);

使用Dynamic Linq库时,如果必须在运行时创建动态查询,则必须使用IQuerable作为初始选择。这意味着var qry = db.table(s => s);而不是var qry = db.table;然后你可以继续链接你的查询,如:qry = qry.Where(bla bla bla);

Found it out the hard way after a few nail biting sessions.

经过几次咬钉会后,发现它很难。

#5


Code:

var allmember = eg_.table.where(x=>x).ToList();

#1


The lambda expression isn't needed:

不需要lambda表达式:

var res = db.StudentDatas;

You could use one but it would be rather pointless:

你可以使用一个,但它会毫无意义:

var res = db.StudentDatas.Select(s => s);

#2


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

SQL的转换由基类库完成。当然,SQL不使用lambda表达式......

#3


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

您不需要lambda表达式。你只想要集合的所有成员。

#4


While both are technically correct, as in they would both give the same result in its simplistic form, this is only because the default behavior of db.table is “Select”. Behind the scenes, they are different. While one is a System.Data.Linq.Table, the other is System.Linq.IQuerable. For example

虽然两者在技术上都是正确的,因为它们都会以简单的形式给出相同的结果,但这只是因为db.table的默认行为是“选择”。在幕后,他们是不同的。虽然一个是System.Data.Linq.Table,另一个是System.Linq.IQuerable。例如

var x = db.table ; var y= db.table(s=>s); 
X = y; 

would result in a compiler error.

会导致编译器错误。

When using the Dynamic Linq library, in cases where you have to create dynamic queries at runtime, you have to use an IQuerable as your initial select. Which means var qry = db.table(s=>s); as opposed to var qry = db.table; Then you can go on and chain your queries like: qry = qry.Where(bla bla bla);

使用Dynamic Linq库时,如果必须在运行时创建动态查询,则必须使用IQuerable作为初始选择。这意味着var qry = db.table(s => s);而不是var qry = db.table;然后你可以继续链接你的查询,如:qry = qry.Where(bla bla bla);

Found it out the hard way after a few nail biting sessions.

经过几次咬钉会后,发现它很难。

#5


Code:

var allmember = eg_.table.where(x=>x).ToList();