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

  • Home
  • SEARCH
  • 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 7927385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:17:03+00:00 2026-06-03T19:17:03+00:00

I have a generic repository that is using Entity Framework 4 with the DbContext

  • 0

I have a generic repository that is using Entity Framework 4 with the DbContext api. When Update is called, the repository registers the entity and the repository with the unit of work object.

When commit is called on the unit of work, and the entity updated is being tracked by EF (normally it is not, as the repository is for ASP MVC and its model binding technology) the type is a proxy type and the an exception is thrown as the type does not exist in the model. The PersistUpdateOf then falls over when the entity is tracked by EF because EF uses proxy classes. The attached image shows this.
enter image description here

Is there a work around that does not involve disabling proxies that will work with entities that are tracked or untracked.

    public void Update<TEntity>(TEntity entity) where TEntity : EntityBase
    {
        //Audit the update
        if (entity is IAuditable)
        {
            (entity as IAuditable).AuditEntityUpdate();
        }

        //Register the entity as Amended with the unit of work
        _unitOfWork.RegisterAmended(entity, this);
    }


    public virtual void PersistUpdateOf(EntityBase entity)
    {
        _context.Set(entity.GetType()).Attach(entity);
        _context.Entry(entity).State = EntityState.Modified;
    }
  • 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-03T19:17:05+00:00Added an answer on June 3, 2026 at 7:17 pm

    Just remove the line that you Attach the entity. Please note that the proxy entity is tracked by the context that created it. If you didn’t Detach it or used AsNoTracking() you will not be able to attach it to another context.

    public virtual void PersistUpdateOf(EntityBase entity)
    {
        _context.Entry(entity).State = EntityState.Modified;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: I have a generic EF repository using DbContext designed
The goal: I'm trying to use the new Entity Framework 4.1 DbContext API (using
Currently in my application and using the unit of work pattern and generic repository,
So basically i have a domain object and a generic repository that can do
I have an application that uses a generic repository pattern for data access. As
I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
So, I am kind of stumped. I have been using a generic repository, and
I am writing a generic repository for entity framework and am confused as to
I have two generic save methods in a repository class: public void Save<T>(T entity)
I have an Entity class that I have extended using the partial class syntax

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.