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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:47:34+00:00 2026-05-26T21:47:34+00:00

I am getting started with Entity Framework using POCO in a model-first configuration. I

  • 0

I am getting started with Entity Framework using POCO in a model-first configuration. I have a slightly non-standard model – generated by customising the .tt file to respond to custom properties in the .edmx enabling me to trigger a NotifyPropertyChanged event for logging updates to certain properties – which results in a class that effectively looks a little like this:

public partial class MyClass: INotifyPropertyChanged
{
    /// <summary>
    /// Catches events to be added to the UserLog
    /// </summary>
    public event PropertyChangedEventHandler PropertyChanged;

    /// <summary>
    /// Notifies any event listeners attached to the PropertyChanged event that a loggable field
    /// update has occurred.
    /// </summary>
    /// <param name="eventType">The type of the field.</param>
    /// <param name="message">The message to record in the logs</param>
    private void NotifyFieldUpdate(string eventType, string message)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new LogEventArgs(eventType, message));
        }
    }


  private  string _myField;
  public virtual string MyField
    {
      get
      {
        return _myField;
      }
      set 
      {
        if ( _myField != value )
          {
        _myField = value;
        NotifyFieldUpdate( "FIELDCHANGE", String.Format("MyField changed to {0}", value) );
          }
        }
      }
  }

The event handler is then configured in another part of the partial class, to avoid unnecessary overwrites.

The problem I have is that if that gets updated twice, it falls over:

  public void TestBehaviour(ObjectContext currentContext)
  {
    MyClass testMe = FetchFromObjectContext(currentContext);
    testMe.MyField = "Hello";
    currentContext.SaveChanges();
    testMe.MyField = "Goodbye";
  }

The moment I call the second of those methods, I hit the following error:

EntityMemberChanged or EntityComplexMemberChanged was called without first calling EntityMemberChanging or EntityComplexMemberChanging on the same change tracker with the same property name. For information about properly reporting changes, see the Entity Framework documentation.

I have tried using currentContext.DetectChanges() and currentContext.Refresh( ... ) but that is really monkey coding as I don’t know what exactly is going on.

My first question is: What is causing the problem and what do I have to do with the ObjectContext in order to avoid this type of error? It seems quite plausible to me that fields could be updated from time to time and I would hate for my system to fall over if it happened twice.

My second, perhaps more in-depth question is: Am I approaching this all wrong by using the INotifyPropertyChanged interface when it appears that the class is firing these EntityMemberChanged events already? I assume this is because the ObjectContext is creating a proxy- does that mean in some cases those methods are likely to be unavailable if I don’t have my own notifications?

  • 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-26T21:47:34+00:00Added an answer on May 26, 2026 at 9:47 pm

    It turns out that the root cause of the problem was, as I suspected, to do with the creation of proxies by my ObjectContext.

    To resolve the error and – in my case – consequently solve the problem, I just needed to add

    currentContext.ContextOptions.ProxyCreationEnabled = false;
    

    to my ObjectContext creation and it prevents it creating proxies. This may cost me a little convenience, but given that they seem somewhat fragile and opaque I think it saves me a lot of hassle for the time being.

    Helpful resource: MSDN on working with POCO entities

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

Sidebar

Related Questions

I am getting started with Entity Framework 4, using model-first development. I am building
I am getting started with Entity Framework using EF4 in VS 2010 RC. So
I am just getting started with Microsoft's Entity Framework, using it for an MVC
I am getting started with the ADO.NET Entity Framework 4.0. I have created an
I am just getting started with the ADO.NET Entity Data Model and I was
Just getting started using MVC in ASP.NET, I'm going to have it so users
So I'm just getting started with Entity Framework. I'm working with a very large,
Just getting started with Lucene.Net. I indexed 100,000 rows using standard analyzer, ran some
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
Getting started with TDD and I want to ground up a Repository-driven Model. However,

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.