'ObjectContext' vs 'DbContext' in Entity Framework

前端 未结 3 1917
南笙
南笙 2020-12-03 03:37

I\'m using the DbContext class within code that I am creating that is based on the Generic Repositories and Unit of Work design patterns. (I am following the gu

3条回答
  •  再見小時候
    2020-12-03 04:18

    We can cast a DBContext to type ObjectContext

    public class MyContext: DbContext
    {
        public DbSet Blogs { get; set; }
       //other dbsets, ctor etc.
    
        public ObjectContext ObjectContext()
        {
            return (this as IObjectContextAdapter).ObjectContext;
        }
    }
    

提交回复
热议问题