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 8570235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:30:44+00:00 2026-06-11T18:30:44+00:00

I am doing this: User user = _usersRepository.SingleOrDefault(u => u.Username == gigi, new string[]

  • 0

I am doing this:

User user = _usersRepository.SingleOrDefault(u => u.Username == "gigi", new string[] { "Roles" });
UnitOfWork.Current.Dispose();

and i don’t get the roles associated to that user, i get that System.ObjectDisposedException.

If instead of doing that repository call , i simply do:

            User user;
            using (MyEntities ctx = new MyEntities ())
            {
                user = ctx.Users.Include("Roles").SingleOrDefault(u => u.Username == "gigi");
            }

i do get the roles.
What am i missing?

LE:This is how my base repository looks like:

    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private DbContext _context;
        private IDbSet<T> _dbSet;

        protected DbContext Context
        {
            get
            {
                if (_context == null)
                {
                    EFUnitOfWork currentUnitOfWork = (EFUnitOfWork)UnitOfWork.Current;
                    _context = currentUnitOfWork.Context;
                }

                return _context;
            }
        }

        protected IDbSet<T> DbSet
        {
            get
            {
                if (_dbSet == null)
                {
                    _dbSet = Context.Set<T>();
                }

                return _dbSet;
            }
        }

        public void Add(T entity)
        {
            DbSet.Add(entity);
        }

        public void Attach(T entity)
        {
            DbSet.Attach(entity);
        }

        public void Delete(T entity)
        {
            DbSet.Remove(entity);
        }

        public void Update(T entity)
        {
            Context.Entry(entity).State = System.Data.EntityState.Modified;
        }

        public T SingleOrDefault(Expression<Func<T, bool>> where, string[] includes=null)
        {            
            if (includes != null)
            {
                foreach (string property in includes)
                {
                    DbSet.Include(property);
                }
            }
            return DbSet.SingleOrDefault(where);
        }

        public IQueryable<T> Get(Expression<Func<T, bool>> where, string[] includes=null)
        {
            if (includes != null)
            {
                foreach (string property in includes)
                {
                    DbSet.Include(property);
                }
            }
            return DbSet.Where(where);
        }
    }
  • 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-06-11T18:30:46+00:00Added an answer on June 11, 2026 at 6:30 pm

    DbSet.Include() returns a new DbSet<T> that includes that navigation property.
    Since you don’t use the returned DbSet, your Include() calls have no effect.

    You need to assign the result of Include() to a local variable and use that instead of DbSet.

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

Sidebar

Related Questions

Currently I am doing this: I have text that looks like: Hello ${user.name}, this
With ASP.net MVC I'm doing this: [HttpPost] [TransactionFilter] public ActionResult Create(User user) { //
I can deny a specific user DB viewing by doing something like this: DENY
In python, I am currently doing this: if user_can_read(request.user, b) == False: Is there
I am doing this: user = User.find( params[:id] ) when I do: user.section_id it
I'm a little confused about the purpose of doing this: module SessionsHelper def current_user=(user)
Here is what I have currently, I'm doing this: current_account.send(object).search(params[:search]).user_id_equals_any(users).visibility_is_any(visibilities) but thats not very
So, I'm doing something like: user.students.includes(:exams).ungraded.paginate(:page => params[:page]).order(exams.created_at desc) However, this causes a subtle
Hi I am doing my project in PHP.In this when the use r doesnt
Im doing this project where i need to download files through a webservice (images,

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.