In the tutorials im following for learning about the entity framework, they keep mentioning entities. I often see it gets used as a synonym for the dbsets<> in the database context class, but what's the literal meaning of it?

I already know how the entity framework works, I just dont understand the meaning of the word.

有帮助吗?

解决方案

In Entity Framework an entity is largely equivalent to a class in the conceptual model (or the class model, which is mapped to the store model).

In domain model terms an entity is

An object that is not defined by its attributes, but rather by a thread of continuity and its identity.

(Source: Wikipedia)

That quite a mouthful for "an object with an identity", as opposed to a value object, like a DateTime or (maybe) an Address. A Customer is an entity, because it is identified by "who" he is. Two customers with the same name are still two customers.

So entities can loosely be defined as the "things" the business domain is about. The things both the customer/user and the system designer/developer talk about in ubiquitous language. And in EF those things are represented by classes.

So it's not the DbSet. The DbSet is a repository that provides entity objects.

I often see people referring to entities as models. I don't know the origin of this terminology (it seems to happen too often to be a coincidence), but I don't think it's correct. It's mostly confusing. The model in EF is either the store model or the conceptual model, so it's a collection of entities. A model can also be a view model that comprises any number of attributes of any number of entities.

其他提示

Lets take a Person object for example and lets say the Person data is being posted to a database and its moving through the tiers

When its in my UI, I call it a Person Model or ViewModel.

When its in my business layer I call it a Person Business Object.

When its in my Data Layer, I call it a Person Entity.

Its the same data that is moving into different objects in different tiers. The entity is just the name of the object that is holding the Person data in the Data Access tier....

An entity is simply an object that represents some form of relational data. This is typically used for representing relational databases, but it is not confined to that. I suggest looking at http://msdn.microsoft.com/en-us/data/aa937709 for a brief overview of how the Entity Framework works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top