2013-02-09 42 views

回答

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

當然由於延遲執行,此查詢將在把主叫執行試圖枚舉的結果。

1
var thePost = (from p in _context.Posts 
        where p.Id == id 
        select p); 
    return thePost;