I've a procedure where I need to save a entity object. The problem is that I don't know if this entity is attached to my datacontext or not. To solve this I use the following code:
try
{
db.ClientUsers.Attach(clientUser);
db.Refresh(RefreshMode.KeepCurrentValues, clientUser);
}
finally { }
db.SubmitChanges();
I'm looking for a better method to detect if an entity belongs to a context and also to test if an entity is attached to a specific context.