How to return empty IQueryable in an async repository method
问题 Lets say I have a simple repository class, with one GetByNames method public class MyRepo { private readonly MyDbContext _db; public MyRepo(MyDbContext db) { _db = db; } public IQueryable<MyObject> GetByNames(IList<string> names) { if (names== null || !names.Any()) { return Enumerable.Empty<MyObject>().AsQueryable(); } return _db.MyObjects.Where(a => names.Contains(a.Name)); } } Now when I use it with async EntityFramework ToListAsync() extension var myObjects = awawit new MyRepo(_db)