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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:32:05+00:00 2026-06-05T20:32:05+00:00

There are many errors here in SO, but this scenario I think its different.

  • 0

There are many errors here in SO, but this scenario I think its different.

I had some code that was working fine, I update one entity, etc. But the problem is that it was being cached, when I disabled caching with AsNoTracking(), then it started to throw this exception;

What I do its the following:
1. In the page I get a EcoBonusRequest.
2. The user clicks a button and it modifies the currentstatus proeprty, and it addsa a list item to a collection of workflowhistories, (an associated collection of the ecobonusrequestobject).
3. I call the udpate method, setting state to modified, here it throwed the exception.

Here is my code>

EcoBonusRequestRepository.cs

public void UpdateEcoBonusRequest(EcoBonusRequest ecoBonusRequest)
            {
                _context.EcoBonusRequests.Attach(ecoBonusRequest);
                _context.Entry(ecoBonusRequest).State = EntityState.Modified;
            }

EcoBonusRequestBL

public void Update(EcoBonusRequest ecoBonusRequest)
        {
            DALFacade.UpdateEcoBonusRequest(ecoBonusRequest);
        }

EcoBonusRequest Page

public void ChangeStatus(EcoBonusRequest ecoBonusRequest, string stepname, string who, string choosenoption)
        {

            ecoBonusRequest.WorkflowHistories = new List<WorkflowHistory>
                                                   {
                                                       new WorkflowHistory()
                                                           {
                                                               Date = DateTime.Now,
                                                               What = choosenoption,
                                                               StepName = stepname,
                                                               Who = who
                                                           }
                                                   };

            ecoBonusRequest.CurrentStatus = _currentStepBlo.StepName;
            var ecoBonusRequestBL = new EcoBonusRequestBL();
            ecoBonusRequestBL.Update(ecoBonusRequest);
        }

This is how I get the object first: (I am not going to paste all code from all layers here)

protected override void OnInit(EventArgs e)
        {
            var requestBaseId = RequestBaseId;
            if (requestBaseId != null)
            {
                EcoBonusRequest request = GetDBRequest(requestBaseId.Value);

In the dal

public IQueryable<EcoBonusRequest> FindEcoBonusRequests(System.Linq.Expressions.Expression<Func<EcoBonusRequest, bool>> predicate)
            {
                return _context.EcoBonusRequests.AsNoTracking().Where(predicate);
            }
  • 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-05T20:32:06+00:00Added an answer on June 5, 2026 at 8:32 pm

    Yeah this is a fun one, the issue here comes from trying to re-attach an entity which is already attached to the context. This can come from a logic error or perhaps you are reusing your context without clearing the attached objects. There is a local collection on the database which you can use to see what items are currently attached to the context.

    ctx.YourEntityCollection.Local
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many questions like this but I can't find one that seems to
There are so many things wrong with the following code, but yet no errors
There are many similar questions, but I didn't find one that gets straight to
I saw that there's many, many thread about this on the web, also in
This might be impossible to answer since there are probably too many variables here,
This question has been brought up many times, but I'd like to ask it
I've had a look around to see if this has been answered, and there
there may be other ways to do this but I'm looking for an fairly
I know this has been asked many times, and answered many times, but, all
Ok I have been working on this for many days and I know I

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.