我见过以下所有内容都被称为LINQ的例子。
var y = _context.Persons;
IQueryable<Person> x = _context.Persons;
var z = from tblPerson in _context.Persons
select tblPerson;它们都是LINQ,只是味道不同,还是只有z LINQ?如果是这样的话,另外两个叫什么名字?如果他们都是LINQ,那么当我在谷歌上搜索关于他们的信息时,我该如何区分这三者呢?对于y和x,我应该在MVC核心中使用var或IQueryable (以及为什么),并且应该在z上使用
发布于 2017-07-28 14:04:51
感谢Jereon的链接。不确定var或IQueryable是否内在地链接到LINQ的实现,或者它是否是一个更通用的问题。是通用的。
从上面的链接中可以找到这种LINQ
from tblPerson in _context.Persons
select tblPerson;被称为
而这个品种的LINQ
db.Person = _context.Persons
.Include(px => px.Gender)
.Include(px => px.Title)
.Include(px => px.AddressIDs)
.ThenInclude(px => px.AddressType)
.Where(px => px.Name.Contains("foo")
.OrderBy(px => px.Name);被称为
至于用法,一般的意见似乎分为两个阵营。
- when using the let keyword
- when you have multiple generators (from clauses)
- when doing joins
以及其他所有东西的扩展方法。
https://stackoverflow.com/questions/45373010
复制相似问题