ecengel
9/26/2018 - 5:13 AM

QueryOptionV4

public interface IQueryOption
    {
        IQueryOption FilterBy(Expression<Func<Contact, bool>> filter);
        IQueryOption AddEagerLoad(Expression<Func<Contact, object>> eagerLoad);
    }

    public class QueryOption : IQueryOption
    {
        internal List<Expression<Func<Contact, object>>> EagerLoads { get; set; }
        internal Expression<Func<Contact, bool>> Filter { get; set; }

        public IQueryOption FilterBy(Expression<Func<Contact, bool>> filter)
        {
            Filter = filter;
            return this;
        }

        public IQueryOption AddEagerLoad(Expression<Func<Contact, object>> eagerLoad)
        {
            if(EagerLoads == null)
                EagerLoads = new List<Expression<Func<Contact, object>>>();

            EagerLoads.Add(eagerLoad);
            return this;
        }
    }