实体框架中的“ ObjectContext”与“ DbContext” [英] 'ObjectContext' vs 'DbContext' in Entity Framework

查看:93
本文介绍了实体框架中的“ ObjectContext”与“ DbContext”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于通用存储库和工作单元设计模式创建的代码中使用 DbContext 类。 (我正在遵循这里。)在处理该项目时,我遇到了 ObjectContext 类。

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 guidance here.) While working on this project I have encountered the ObjectContext class.

我读过很多讨论 ObjectContext DbContext 。虽然我读过的书中有些书是有道理的,但我仍然对这些差异还没有完全的了解,这让我对当前的实现感到疑惑。我应该使用 DbContext ObjectContext 还是两者都使用?

I've read quite a number of posts that discuss ObjectContext vs. DbContext. While some of what I've read makes sense, I still don't have a complete understanding of the differences and this leaves me wondering about my current implementation. Should I be using DbContext, ObjectContext or both? Is using one of these now considered an anti-pattern?

推荐答案

DbContext 只是 ObjectContext 的包装。

DbContext 只是一组API,比 ObjectContext 公开的API更易于使用。

DbContext is just a set of APIs that are easier to use than the APIs exposed by ObjectContext.

无论如何,此处,您将找到一个非常简单的Visual Studio模板,该模板使用存储库模式和实体框架。

Anyway, here you'll find a very simple Visual Studio template that uses the Repository Pattern and the Entity Framework.

这篇关于实体框架中的“ ObjectContext”与“ DbContext”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆