1

在 web api 中,不使用的数据.ToList()也发送到 api,但是如何?这是我的 LINQ 查询,我不使用,.ToList()但我的数据也发送到浏览器。谁能告诉我区别或描述它是如何工作的?

using (var _context = new iCMEFModelCon())
                {
                    return _context.UserResidents.Where(c => c.ResidentId == residentId)
                        .Select(c => new
                        {
                            UserId = c.User.Id,
                            UserName = ((c.User.FirstName ?? "") + " " + (c.User.LastName ?? "")).Trim()
                        });
                }
4

1 回答 1

1

查询的返回类型是 IEnumerable 或 IQueryable:

Linq 数据库查询的结果通常IQueryable< T>来自IEnumerable< T>, IQueryable,IEnumerable

如果您的数据源是IEnumerable,则结果类型为IEnumerable< T>

寻找更多

于 2017-08-23T10:08:27.637 回答