Die Instanz des Entitätstyps kann nicht verfolgt werden, da bereits eine andere Instanz dieses Typs mit demselben SchlüsC#

Ein Treffpunkt für C#-Programmierer
Guest
 Die Instanz des Entitätstyps kann nicht verfolgt werden, da bereits eine andere Instanz dieses Typs mit demselben Schlüs

Post by Guest »

Ich habe ein Serviceobjekt-Update

Code: Select all

public bool Update(object original, object modified)
{
var originalClient = (Client)original;
var modifiedClient = (Client)modified;
_context.Clients.Update(originalClient); // x.Id == searchId)
.Include(x => x.Opportunities)
.ThenInclude(x => x.BusinessUnit)
.Include(x => x.Opportunities)
.ThenInclude(x => x.Probability)
.Include(x => x.Industry)
.Include(x => x.Activities)
.ThenInclude(x => x.User)
.Include(x => x.Activities)
.ThenInclude(x => x.ActivityType);
}
Irgendwelche Ideen?

Ich habe mir die folgenden Artikel/Diskussionen angesehen. Ohne Erfolg: ASP.NET GitHub Issue 3839

UPDATE:

Hier sind die Änderungen an GetAsNoTracking:

Code: Select all

public Client GetAsNoTracking(long id)
{
return GetClientQueryableObjectAsNoTracking(id).FirstOrDefault();
}

Code: Select all

GetClientQueryableObjectAsNoTracking
:

Code: Select all

private IQueryable GetClientQueryableObjectAsNoTracking(long searchId)
{
return _context.Clients
.Where(x => x.Id == searchId)
.Include(x => x.Opportunities)
.ThenInclude(x => x.BusinessUnit)
.AsNoTracking()
.Include(x => x.Opportunities)
.ThenInclude(x => x.Probability)
.AsNoTracking()
.Include(x => x.Industry)
.AsNoTracking()
.Include(x => x.Activities)
.ThenInclude(x => x.User)
.AsNoTracking()
.Include(x => x.Activities)
.ThenInclude(x => x.ActivityType)
.AsNoTracking();
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post