C# 从LINQ查询返回对象而不将其强制转换为列表

C# 从LINQ查询返回对象而不将其强制转换为列表,c#,asp.net,linq,C#,Asp.net,Linq,当我将返回值设置为列表时,我有一个LINQ查询工作,但是我只想返回一个IQueryable。我该怎么做 public List<Post> GetPostByID(int id) { var thePost = (from p in _context.Posts where p.Id == id select p).ToList(); return thePost; } public Lis

当我将返回值设置为
列表
时,我有一个LINQ查询工作,但是我只想返回一个
IQueryable
。我该怎么做

public List<Post> GetPostByID(int id)
{
    var thePost = (from p in _context.Posts
                   where p.Id == id
                   select p).ToList();
    return thePost;
}
public List GetPostByID(int-id)
{
var thePost=(来自_context.Posts中的p
其中p.Id==Id
选择p.ToList();
返回邮件;
}
公共IQueryable GetPostByID(int id)
{
返回(来自p in_context.Posts
其中p.Id==Id
选择p);
}
当然,由于延迟执行,此查询将在调用方尝试枚举结果的put处执行。

public IQueryable GetPostByID(int-id)
{
返回(来自p in_context.Posts
其中p.Id==Id
选择p);
}
当然,由于延迟执行,此查询将在调用方尝试枚举结果的put处执行

var thePost = (from p in _context.Posts
                   where p.Id == id
                   select p);
    return thePost;
 public IQueryable<Post> GetPostByID(int id)
 {
        return (from p in _context.Posts
                       where p.Id == id
                       select p);
 }