entity framework DbContext Attach判断

 DbEntityEntry<T> entry = db.Entry<T>(model);

 if (entry.State == EntityState.Detached)
     db.Set<T>().Attach(model);
原文地址:https://www.cnblogs.com/msbbc/p/3072943.html