Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7685643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:17:51+00:00 2026-05-31T19:17:51+00:00

I have turned off lazy loading and the proxy creation on my DbContext. I

  • 0

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:

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 UoW:

        public IDbSet<TEntity> CreateSet<TEntity>() where TEntity : class
        {
            return base.Set<TEntity>();
        }

I query the context via 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 in an array of expressions to be included in my query. So I might call it like this:

var users = userRespository.Get(u => u.Id == SomeGuid, u => u.UserType);

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?

Update:

I am thinking before I call the base.Set I would need to add the includes there. Not sure though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:17:52+00:00Added an answer on May 31, 2026 at 7:17 pm

    All extensions methods on IQueryable usually works in the way that they produce 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 quite similar to my older solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have turned computer monitor off using this command SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)(turnOff ?
I use Cocoa Emacs 23.1.91 and I want to always have hl-line-mode turned off
I'm using ant scp task in a loop and i have turned off failonerror.
I have turned off compatibility mode for IE9 but dojo.isIE is still showing 8
OK. I have turned off AutoDetectChangesEnabled, and when I query the context, modify an
i have turned off index.php in my codeigniter by .htaccess and also i left
I'm using jQuery Mobile and have turned off the default AJAX handling of forms
I have turned off all of the intelligent typing preferences that I can find
setup Using Dreamweaver CS 5.5 / Windows 7 I have turned off 'Preview [in
I have turned headers off in the report server config file and am attempting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.