为什么LINQ设计人员今天不坚持使用sql编写方式? [英] Why didn't the LINQ designers stick with using the way sql is written today?

查看:63
本文介绍了为什么LINQ设计人员今天不坚持使用sql编写方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,为什么要在LINQ中这样做

For example, why do you do this in LINQ

var products = from p in Products
               select p.Name;

什么时候可以这样做:

var products = select p.Name from Products p;

第二个在linq中提供一些限制吗? 也许上面的例子太简单了,以至于无法真正理解为什么linq是用一种顺序编写而sql是用另一种顺序编写.

Does the second offer some limitations in linq? Maybe the above examples are too simple to actually see why linq is written in one order and sql is written in another.

推荐答案

因为LINQ不是SQL. LINQ由IEnumerable<T>上的许多链接扩展方法组成(当您使用System.Linq命名空间时).类似SQL的语法只是一个编译器技巧,可以在此类查询方法的链上启用一些语法糖,因此看起来您可以在.NET语言中使用看起来像SQL的查询. LINQ基本上与SQL无关...

Because LINQ is not SQL. LINQ consists of a number of chained extension methods on IEnumerable<T> (when you are using the System.Linq namespace). The SQL like syntax is just a compiler trick to enable some syntactic sugar on chains of such query methods so it appears you can use queries looking a bit like SQL inside .NET languages. LINQ basically has nothing to do with SQL per se...

这篇关于为什么LINQ设计人员今天不坚持使用sql编写方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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