correct layer for Complex linq queries ?

Nov 6, 2015 at 1:00 PM
Edited Nov 6, 2015 at 1:05 PM
Hello,

First let me thank the author for the great effort in a project like this.

I have a question regarding getting data from Business layer.
I Know some persons are using EF linq queries in Business Layer, can you explain the reason to use it in DATA?

I see that the queries are generic but I can find them in DATA layer, for example:
            public List<Leave> Select(int maximumRows, int startRowIndex, string sortExpression,
            string employee, LeaveCategories? category, LeaveStatuses? status)
        {
            using (var db = new DbContext(CONNECTION_NAME))
            {
                // Store the query.
                IQueryable<Leave> query = db.Set<Leave>();

                // Append filters.
                query = AppendFilters(query, employee, category, status);

                // Sort and page.
                query = query.OrderBy(sortExpression)
                        .Skip(startRowIndex).Take(maximumRows);

                // Return result.
                return query.ToList();
            }
        }
In past I used EF queries in the Business/Logic layer, leaving DATA just the default files generated by EF. I just used bellow methods in my Business layers for example:
        public static IEnumerable<Part> GetList(int iRegionId)
        {
            var vPart = new List<Part>();

            Data.DbEntities DbCont;
            using (DbCont = new Data.DbEntities())
            {
                    vPart = (from p in DbCont.Part
                            where p.RegionID == iRegionId 
                            select new Part
                            {
                                PartID = p.PartID,
                                Name = p.Name,
                                Description = p.Description,
                                PartTypeID = p.PartTypeID,
                                SupplierID = p.SupplierID,
                                Height = p.Height
                            }).ToList();
            } 
            return vPart;
        }
This linq query is not very complex, but I used them in business layer before sending to presentation layer.
Nov 6, 2015 at 3:26 PM
Marked as answer by hedzx on 11/6/2015 at 8:26 AM
Coordinator
Aug 4, 2016 at 11:53 PM
Hi,

The idea design to is to have all data technology related components and queries to stay in the DACs. You should only use BCs to consume the methods from DACs. You may however, perform extra business processing i.e. perform computation for some properties, business logic level filtering and etc.

Best Regards