Use IncludeMultiple in method

I use the Ladislav Mrnka extension method:

public static IQueryable<T> IncludeMultiple<T>(this IQueryable<T> query, params Expression<Func<T, object>>[] includes) where T : class { if (includes != null) { query = includes.Aggregate(query, (current, include) => current.Include(include)); } return query; } 

I used the following method here (after a little change):

 public virtual IEnumerable<T> Get( Expression<Func<T, bool>>[] filters = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, string includeProperties = "") { IQueryable<T> query = GetQuery(); if (filters != null) { foreach (var filter in filters) { query = query.Where(filter); } } foreach (var includeProperty in includeProperties.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProperty); } if (orderBy != null) { query = orderBy(query); } return query; } 

I want to use IncludeMultiple instead of strings in the includeProperties variable. So, I changed the function:

 public virtual IEnumerable<T> Get( Expression<Func<T, bool>>[] filters = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, params Expression<Func<T, object>>[] includes) { IQueryable<T> query = GetQuery(); if (filters != null) { foreach (var filter in filters) { query = query.Where(filter); } } if (includes.Length > 0) { query = query.IncludeMultiple(includes); } if (orderBy != null) { query = orderBy(query); } return query; } 

Now I'm a little confused. This method is defined in the class where the GetQuery () method (repository implementation) is defined. But in case I want to execute this method, I would first use GetQuery () ..
I'm right?
Is it better to use this as an extension for IQueryable?

+4
source share
1 answer

No, you do not need to use this method after calling GetQuery , because calling GetQuery is the first command of this method. You can use either GetQuery or Get , depending on your needs. The Get method is actually very good, because it also hides. Using it as a repository method is much better than using it as an extension method in the case of unit testing and bullying.

0
source

All Articles