使用Code First approch或POCO写作类有什么区别?(What is the difference between writting class using Code First approch or POCO?)

EF和ORM。

我最近意识到可以使用POCO来获得干净的类,而不是使用EF自动生成的代码。

我看到了EF 4.1的新版本以及Code First方法和DbContext的使用。

我的问题:

Code First方法和Poco方法有什么区别? 我们可以使用Code First(DbContext和DbSet)代替POCO + Repository模式吗?

谢谢你的时间。

EF and ORM.

I recently realized that is possible using POCO to have clean classes not plumbed with EF auto generated code.

I saw the new release of EF 4.1 and the use of Code First approach and DbContext.

My questions:

What is the difference between Code First approach and Poco approach? Can we use Code First (DbContext and DbSet) instead of POCO + Repository pattern?

Thanks for your time on this.

最满意答案

它们是完全不同的东西,你可以一起使用它们。

POCO意味着您的实体类是“普通”类,不依赖于任何特定的ORM层。

DbContext是一个对象,使您能够以面向对象的方式访问数据库(如早期版本的EF中的ObjectContext )。

看一下这个教程的例子。

They're completely different things, and you can use them together.

POCO means that your entity classes are "normal" classes, not dependent on any specific ORM layer.

A DbContext is an object that enables you to access the database in an object-oriented way (like ObjectContext in earlier versions of EF).

Have a look at this tutorial for examples.

更多推荐