使用"DbContext"而不是"ObjectContext"总是更好吗? [英] Is it always better to use 'DbContext' instead of 'ObjectContext'?
问题描述
我刚刚下载了EntityFramework.dll v4.3
.我发现了许多将DbContext
与ObjectContext
进行比较的问题.但是其中大多数来自2010年或2011年初.
I just downloaded EntityFramework.dll v4.3
. I've found a number of questions that compare DbContext
vs. ObjectContext
. But most of these are from 2010, or early 2011.
我想了解更多有关该主题的信息.具体来说,我可以尝试使用DbContext
上的任何书籍吗?从今天起,我还想知道DbContext
与它的哥哥ObjectContext
相比有哪些局限性?
I'd like to read more on the subject. Specifically, are there any books on DbContext
I can get my hands on? I also want to know, as of today, what are the limitations of DbContext
when comparing it to its older brother the ObjectContext
?
我意识到DbContext
更加紧凑,因为它公开的属性更少.这向我建议我应该从ObjectContext
迁移.但是,如果执行此迁移,是否会放弃任何功能?例如,我读到DbContext
不具有STE(自我跟踪实体)功能.这是否仍然成立,这是否令人担忧?
I realize that DbContext
is more compact in that it exposes fewer properties. This suggests to me that I should migrate from ObjectContext
. But, if I do this migration, will I give up any capabilities? For example, I've read that DbContext
doesn't have the STE (Self-tracking entities) capability. Does this still hold true and is it a concern?
推荐答案
我想了解更多有关该主题的信息.具体来说,有没有 可以在
DbContext
上读书吗?
I'd like to read more on the subject. Specifically, are there any books on
DbContext
I can get my hands on?
您的问题并非一开始就好,因为单个Google查询将为您提供答案.有一本关于DbContext本身的优秀书籍—它不包含有关代码优先"方法的任何内容,但是我想那真的不是您要问的重点.
Your question does not start off well because a single Google query will give you an answer for this. There is an excellent book about DbContext itself — it doesn't contain anything about the Code First approach, but I guess that is really not the point of your question.
我发现了许多将
DbContext
与.c1进行比较的问题.ObjectContext
.但是其中大多数来自2010年或2011年初.
I've found a number of questions that compare
DbContext
vs.ObjectContext
. But most of these are from 2010, or early 2011.
如果只想将ObjectContext
+ EDMX替换为DbContext
+ EDMX,则比较仍然相同. DbContext
是ObjectContext
的包装,并且其功能集没有增长,除了与Code First和Migrations有关的那些功能.
If you just want to replace ObjectContext
+ EDMX with DbContext
+ EDMX, the comparison is still the same. DbContext
is a wrapper around ObjectContext
and its feature set didn't grow up except with respect to those features related to Code First and Migrations.
我意识到
DbContext
更加紧凑,因为它展示的内容更少 特性.这向我建议我应该从ObjectContext
.
I realize that
DbContext
is more compact in that it exposes fewer properties. This suggests to me that I should migrate fromObjectContext
.
是的,它更加紧凑,并且简化了与上下文相关的最常见任务.对于更复杂的任务,您仍然可以通过IObjectContextAdapter
将DbContext
实例转换为ObjectContext
实例.
Yes, it is more compact and it simplifies most common tasks that you have to do with the context. For more complex tasks, you can still convert a DbContext
instance to an ObjectContext
instance through IObjectContextAdapter
.
但是,如果执行此迁移,我会放弃任何功能吗?为了 例如,我读到
DbContext
没有STE(自我跟踪 实体)能力.这是否仍然成立,这是否令人担忧?
But, if I do this migration, will I give up any capabilities? For example, I've read that
DbContext
doesn't have the STE (Self-tracking entities) capability. Does this still hold true and is it a concern?
STE是为ObjectContext
创建的,我不认为它已移植到DbContext
,但是您可以尝试自己实现此功能.
STE was created for ObjectContext
and I don't think it was ported to DbContext
, but you can try to implement this capability yourself.
STE只是具有解决某些问题的想法的模板.它似乎是一个很好的理论解决方案,但由于对于现实世界的解决方案来说并不是很好,因此并没有被开发人员社区很好地接受.这也是为什么开发其他更重要的功能而不是改进或移植模板的原因.
STEs are just a template with an idea to solve some problem. It appeared as a good theoretical solution but it wasn't very well accepted by the developer community because the solution is not very good for real world scenarios. It is also the reason why other more important features are being developed instead of improving or porting the template.
这篇关于使用"DbContext"而不是"ObjectContext"总是更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!