Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Multiple instances of IEntityChangeTracker after Update #2478


User avatar
0
eggersa created

Hello

I got an error after I updated from 0.8.4 to 0.9.1.1 I did not have before:

When I invoke the following method:

public async Task CreateEvent(EventEditDto input)
        {
            var @event = input.MapTo<Event>();
            @event.Attendees = new List<User>();

            for (int i = 0; i < input.AttendeeIds.Length; i++)
            {
                var attendee = await UserManager.FindByIdAsync(input.AttendeeIds[i]);
                @event.Attendees.Add(attendee);
            }

            await _eventRepository.InsertAsync(@event); // exception here
        }

I get the error

An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

I get a similar error when I invoke

var entries = ChangeTracker.Entries().ToList();

in my override of ApplyAbpConcepts() in the MyCompanyDbContext class.

The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.

Obviously there are now multiple DbContexts. How can I handle this properly? Looking forward for your help and thank you in advance ;).


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you add [UnitofWork] attribute to CreateEvent method and see if it works ?

  • User Avatar
    0
    eggersa created

    Hi.

    Turned out it was a bug in the framework that was addressed in the later version 0.9.3. After I did update to this version the problem was solved.