Entity Framework Code First - No Detach() method on DbContext

后端 未结 4 2037
北恋
北恋 2020-11-27 03:42

I\'m wondering why there is no Detach method on the DbContext object like there is for ObjectContext.  I can only assume this omission was intentional, but I have a hard tim

4条回答
  •  伪装坚强ぢ
    2020-11-27 04:28

    I usually extend the base class(inherits from the DbContext) with the property:

    public class MyDbContext : DbContext
    {
        public ObjectContext ThisObjectContext
        {
            get
            {
                return ((IObjectContextAdapter)this).ObjectContext;
            }
        }
    }
    

    later you can use this property for variety of useful stuff ... like Detach :)

提交回复
热议问题