当我将返回值设置为a时List,我有一个LINQ查询,但是我只想返回一个IQueryable<Post>.我该怎么办?
public List<Post> GetPostByID(int id)
{
var thePost = (from p in _context.Posts
where p.Id == id
select p).ToList();
return thePost;
}
Run Code Online (Sandbox Code Playgroud)
public IQueryable<Post> GetPostByID(int id)
{
return (from p in _context.Posts
where p.Id == id
select p);
}
Run Code Online (Sandbox Code Playgroud)
当然,由于延迟执行,此查询将在调用者尝试枚举结果的put处执行.
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |