“模型”与“模型”之间有什么区别?和“上下文”在实体框架行话? [英] What is the difference between a "Model" and a "Context" in Entity Framework jargon?

查看:261
本文介绍了“模型”与“模型”之间有什么区别?和“上下文”在实体框架行话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Entity Framework行话中,模型和上下文有什么区别?

What is the difference between a "model" and a "context" in Entity Framework jargon?

我正在应用程序中使用实体框架数据库优先方法。在我阅读有关EF实施策略的不同论坛和文章时,这些​​术语已经出现了很多次。我似乎无法弄清楚这两者有何不同(甚至不只是实体框架,而是一般的软件开发)。人们使用这些词就好像它们是不同的一样,但是有些人似乎可以互换使用这些词。

I'm using the Entity Framework database first approach in an application. These terms have come up many times as I've been reading different forums and articles on EF implementation strategies. I can't seem to figure out how these two are different (not even with just entity framework, but with software development in general). People use the words as if they are different, but then some people seem to use the words interchangeably.

推荐答案

上下文

这是简单。上下文是 DbContext 或更旧的 ObjectContext 类,它是实体框架数据访问层的核心。它通过强大的类型化实体集提供透明的数据库访问,跟踪和保存更改,管理数据库事务和连接,并包含许多实用程序方法来简化所有类型的数据访问任务(尤其是 DbContext )。

This is easy. The context is either the DbContext or the older ObjectContext class that is the core of the entity framework data access layer. It supplies transparent database access through strong typed sets of entities, tracks and saves changes, manages database transactions and connections, and contains a number of utility methods to facilitate all kinds of data access tasks (esp. DbContext).

模型

这可以是两个(或三)。

This can be two (or three) things.


  • 数据模型或存储模型。这是EF数据访问层下面的数据库的关系模型。

  • 概念模型或类模型。这是代表数据库的.Net类模型。该模型可以由EF(数据库优先)生成,也可以是现有的类模型(代码优先)。概念模型和商店模型通过 mapping 链接在一起,因此EF知道如何从数据库记录中填充.Net类,以及如何将.Net类保存到数据库中。

  • 有人将概念模型中的类称为模型。这没错,但是我更喜欢使用名称实体

  • The data model, or store model. Which is the relational model of the database underlying the EF data access layer.
  • The conceptual model, or class model. Which is the .Net class model that represents the database. This model can either be generated by EF (database-first) or it can be an existing class model (code first). The conceptual model and the store model are linked through mapping, so EF knows how to populate .Net classes from database records and, conversely, how to save .Net classes to the database.
  • Some people refer to the classes in the conceptual model as "models". This is not wrong, but I prefer to use the name entities for this.

所以 context model 是两件事。您可能会说上下文是两种不同类型的模型之间的中间人。

So context and model are two quite different things. You might say that the context is the middleman between two different types of models.

这篇关于“模型”与“模型”之间有什么区别?和“上下文”在实体框架行话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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