ecengel
9/26/2018 - 3:34 AM

Contact Service Sample 2

 public class ContactService
    {
        private readonly SampleContext _dbContext;

        public ContactService(SampleContext dbContext)
        {
            _dbContext = dbContext;
        }

        public List<Contact> Contacts(Expression<Func<Contact, bool>> filter,
            params Expression<Func<Contact, object>>[] eagerloads)
        {
            var dbSet = _dbContext.Contacts;
            foreach (var eagerload in eagerloads)
                dbSet.Include(eagerload);

            return dbSet.Where(filter).ToList();
        }
    }