Call DbContext.Set <T> (). Does Include () not request included properties?
I disabled lazy loading and proxy creation on my DbContext. I am using Parposer Repository and UnitOfWork. My UnitOfWork inherits from DBConext. Here is an example of what I am doing:
public class User { public Guid Id {get;set;} public virtual Guid UserTypeId {get;set;} //foreign key to UserType and setup in the EF fluent mappings and it does load if I am using lazy loading. public virtual UserType {get;set;} } public class UserType { public Guid Id {get;set;} public string Name {get;set;} } This is inside my wow:
public IDbSet<TEntity> CreateSet<TEntity>() where TEntity : class { return base.Set<TEntity>(); } I request the context through my repository:
protected Expression<Func<TEntity, object>>[] Includes; public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> criteria, params Expression<Func<TEntity, object>>[] includes) { Includes = includes; return GetSet().Where(criteria) .AsEnumerable(); } public IDbSet<TEntity> GetSet() { var set = _unitOfWork.CreateSet<TEntity>(); if(Includes != null) { foreach (var include in Includes) { set.Include(include); } } return set; } So, as you can see, I am passing an array of expressions to be included in my request. Therefore, I can call it as follows:
var users = userRespository.Get(u => u.Id == SomeGuid, u => u.UserType); Custom type is not included in the request, and I do not know what. Should I call something other than Set on DbContext?
Update :
I think before I call the base. Configure, I will need to add there. Not sure though.
All extension methods on IQueryable usually work in such a way that they create a new IQueryable , so you must assign it if you want to get the effect:
public IDbSet<TEntity> GetSet() { var set = _unitOfWork.CreateSet<TEntity>(); if(Includes != null) { foreach (var include in Includes) { set = set.Include(include); } } return set; } Btw. It looks very similar to my old solution .