Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling DbContext.Set<T>().Include() is not querying the included properties?
    primarykey
    data
    text
    <p>I have turned off lazy loading and the proxy creation on my DbContext. I am employing the Repository partern and UnitOfWork. My UnitOfWork inherits from DBConext. Here is an example of what I am doing:</p> <pre><code>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;} } </code></pre> <p>This is inside my UoW:</p> <pre><code> public IDbSet&lt;TEntity&gt; CreateSet&lt;TEntity&gt;() where TEntity : class { return base.Set&lt;TEntity&gt;(); } </code></pre> <p>I query the context via my Repository:</p> <pre><code> protected Expression&lt;Func&lt;TEntity, object&gt;&gt;[] Includes; public IEnumerable&lt;TEntity&gt; Get(Expression&lt;Func&lt;TEntity, bool&gt;&gt; criteria, params Expression&lt;Func&lt;TEntity, object&gt;&gt;[] includes) { Includes = includes; return GetSet().Where(criteria) .AsEnumerable(); } public IDbSet&lt;TEntity&gt; GetSet() { var set = _unitOfWork.CreateSet&lt;TEntity&gt;(); if(Includes != null) { foreach (var include in Includes) { set.Include(include); } } return set; } </code></pre> <p>So, as you can see I am passing in an array of expressions to be included in my query. So I might call it like this:</p> <pre><code>var users = userRespository.Get(u =&gt; u.Id == SomeGuid, u =&gt; u.UserType); </code></pre> <p>The UserType is not being included in the query and I don't know what. Should I be calling something other than Set on the DbContext?</p> <p><strong>Update</strong>: </p> <p>I am thinking before I call the base.Set I would need to add the includes there. Not sure though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload