C# Select * from TableName的Lambda表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1131286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 08:56:32  来源:igfitidea点击:

Lambda Expression of Select * from TableName

c#linqc#-3.0

提问by Wondering

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 StudentDatais name of the table.

我只想知道Select * from TableName. 就像在普通的 LINQ 中一样var res=from s in db.StudentDatas select s;这StudentData是表的名称。

Thanks.

谢谢。

采纳答案by Garry Shutler

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);

回答by yieldvs

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

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

回答by Richard Berg

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 表达式...

回答by Dave Ituru

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.tableis “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 IQuerableas 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 库时,如果您必须在运行时创建动态查询,则必须使用 anIQuerable作为初始选择。这意味着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.

经过几次咬指甲的会议后,很难找到它。

回答by Chandan Rajbhar

Code:

代码:

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