简体   繁体   中英

How to make Repository Methods Async?

I have the following methods on a Entity Framework 6 generic Repository:

public void Add<T>(T entity) where T : class {
  _context.Set<T>().Add(entity);
} // Add

public void Add<T>(Expression<Func<T, Boolean>> criteria) where T : class {
  _context.Set<T>().AddRange(_context.Set<T>().Where(criteria));
} // Add

public IQueryable<T> Find<T>(Expression<Func<T, Boolean>> criteria) where T : class {
  return _context.Set<T>().Where(criteria);
} // Find

How can I make these methods async?

Thank You, Miguel

I really don't think you should force your repository to be async. What you should do instead is to make async your business logic, that would eventually reference your repositories and access them as needed. Your data access shouldn't know anything about the way it will be used somewhere else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM