Is is possible to check if an object is already attached to a data context in Entity Framework?

A simpler approach is:

 bool isDetached = context.Entry(user).State == EntityState.Detached;
 if (isDetached)
     context.Users.Attach(user);

Leave a Comment