Given the following code:
void MergeDbContext(DbContext aSourceDbContext, DbContext aDestinationDbContext)
{
var sourceEntities = aSourceDbContext.ChangeTracker.Entries().ToList();
foreach (DbEntityEntry entry in sourceEntities)
{
object entity = entry.Entity;
entry.State = EntityState.Detached;
// check if entity is all ready in aDestinationDbContext if not attach
bool isAttached = false;// TODO I don't know how to check if it is all ready attched.
if (!isAttached)
{
aDestinationDbContext.Set(entity.GetType()).Attach(entity);
}
}
}
How can I generically determine if an entity exists in the context.