Leaking Quriable objects to upper layers RRS feed

  • Question

  • Hi All,

    i have an application that is flexible, that the user can:

        1. Filter by any field
        2. Sort by any multiple of fields.
        3. And because it will run in ASP.Net, i will also have paging in it.
        4. For network performance, it will send projection on the required fields that will be shown.

    So if i include in each "Service" method, a parameter "UQueryConstraints", that can send filter expression + oderBy expression + page numbers + Projection of the fields, to be used by the Repository, which will apply it to the DBContext, is this is going to be considered a Data leak to the domain services or not?

    Layered Project

    layered project

    notice "UQueryConstraints", it will not leak any "IQueryable".

    public class UIView
        public static void Display()
            object constraintsB = new UQueryConstraints<Car>().Filter(x => x.carNo <= 6).SortBy(x => x.eName).Page(1, 5);
            //.Projection( field1, field2, field3)
            Debug.WriteLine("---------------test CarModel -------------------");
            CarModel carModel1 = new CarModel();
    public class CarModel
        private CarService _carService = new CarService();
        void printCars(UQueryConstraints<Car> constraints)
            foreach ( c in _carService.getCarsList("", constraints)) {
                Debug.WriteLine("Reading from converted back: aName =" + c.aName + ", eName = " + c.eName);
    public class CarService
        public IList<Car> getCarsList(string Text, UQueryConstraints<Car> constraints)
            object dbContextScopeFactory = new DbContextScopeFactory();
            object ambientDbContextLocator = new AmbientDbContextLocator();
            using (dbContextScope == dbContextScopeFactory.Create()) {
                //after creating the Scope:
                //1. create the repository
                //2. call repository functions
                object carRep = new CarRepository(ambientDbContextLocator);
                return carRep.getCarsList("", constraints);
    public class CarRepository : URepositoryFramwork.URepository<Car, AddressDAL.POCOContext.AddressContext>
        public CarRepository(IAmbientDbContextLocator contextLocator)
        public IList<Car> getCarsList(string Text, UQueryConstraints<Car> constraints)
            object query = this.DataSet.Where(constraints.FilterExpression);
            IList<Car> items;
            if (constraints == null) {
                items = query.ToList();
            } else {
                items = constraints.ApplyTo(query).ToList();
            return items;

    Regards. .

    Friday, October 16, 2015 6:13 PM

All replies

  • I have no clue as to what you are talking about with some data leak. Are you trying to use n-tier here or think you are using n-tier?



    Saturday, October 17, 2015 9:20 PM