What's an entity in entity framework?

南笙酒味 提交于 2019-12-11 06:59:59

问题


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.


回答1:


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.




回答2:


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....




回答3:


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.



来源:https://stackoverflow.com/questions/16461807/whats-an-entity-in-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!