这两个查询之间有什么区别 [英] what is the difference between this two queries

查看:95
本文介绍了这两个查询之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from x in  Courses
where x.CourseName=="New Course1"
select x




Courses
   .Where (x => (x.CourseName == "New Course1"))





这两个提供相同的结果。

哪一个更好性能,它们之间有什么区别。

你建议使用什么。





谢谢



This two providing same result.
Which one is better in performance, and what is the difference between them .
what you suggest to use.


Thank you

推荐答案

语法。一种是使用看起来更像SQL的语法,另一种是使用方法调用(可以链接)。它们都做同样的事情,虽然有一些方法使用一种方法或另一种方法更容易,并且可能两者都生成完全相同的SQL,特别是对于这样简单的查询。



这是LINQ代码,因此从数据库中删除了一层。数据库看不到这一点,它看到了这个转入的SQL。
The syntax. One is using the syntax that is made to look more like SQL, the other is using a method call ( which can be chained ). They both do the same thing, although there are some things that are easier with one approach or the other, and probably both generate exactly the same SQL, especially with a query as simple as this.

This is LINQ code, so it's one layer removed from the database. The database does not see this, it sees the SQL this gets turned in to.


第一个是理解查询

第二个是 Lamda 表达式



Lamda更快比理解查询,因为理解查询是转换为Lamda 表达式内部



理解查询是sql之类的构造。这对于更熟悉sql的程序员会有所帮助。
First one is the Comprehension query
second one is the Lamda expressions

Lamda is faster than Comprehension query, since the Comprehension query is converted to Lamda expression internally.

Comprehension query is the sql like construction. This will be helpful for the programmers who are more familiar with sql.


它使用不同的方法来获取相同的数据(显然)。一个使用Linq查询,另一个使用集合上的Linq扩展。



就性能而言,它们可能都差不多。
It uses different ways to get the same data (obviously). One uses a Linq query, the other uses Linq extensions on the collection.

As far as performance, they are probably both around the same.


这篇关于这两个查询之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆