(C#) What is an entity?
Asked Answered
K

7

15

I try to read C# ECMA to find out what an entity is but failed. Is this a instance of class? Or types+members? Or any single word in the code that shows no red wavy line under it?

Kokand answered 3/1, 2018 at 9:9 Comment(2)
Possible duplicate of What is an Entity? Why is it called Entity?Amity
An imperfect but easier start is: an entity is a class (that represent a db table) with properties (that represent db columns). When you instantiate the class, you create an object from the entity which you can perform operation in memory. If we're talking about Entity Framework, that basically expose/provides you with methods and properties on the entity object so we can write less code as it was in ado.net.Pelagi
F
11

Entity is a semantic i.e. relating to meaning in language or logic. An entity is something that exists in itself, actually or potentially, concretely or abstractly, physically or not. It needs not be of material existence.

enter image description here

An entity usually refers to something, anything really, that has a unique and separate existence. In software development this word is almost only used to denote that one instance is different from another instance and they are independent of each other.

A class, on the other hand, defines or contains the definition of an object. Once that object is constructed based on the definition, then you get your instance or object instance.

Hope it helps ;)

Filmore answered 3/1, 2018 at 9:11 Comment(0)
S
9

In C# term entity is commonly related to database representation of the table and should contain an Id attribute.

Suzettesuzi answered 3/1, 2018 at 9:33 Comment(2)
Not really. A CaseFile would be an entity, but it could contain data from dozens of tables, person table, address table, Facility table, claims table, etc. It would have a list of claims, each having a list of services rendered and billed, maybe a list of primary care physicians, with begin and end dates, etc. The entity or in this case, casefile, doesn't care what the underlying database looks like, it has it's own structure.Proselyte
Like this answer, straight forward, easy to understand. The chosen answer actually or potentially, concretely or abstractly, physically or not. is more confusing.Cubature
N
3

Generally, an entity is a unit of existence, an existing or real thing. Something that can have properties ascribed to it that distinguishes it from another unit with similar characteristics.

I have a table and you have a table. If I describe my table in enough detail then at some point it will be possible to distinguish my table from yours.

In object-oriented programming an entity corresponds to an object instance. In data modelling it corresponds to a unit of data rather than something necessarily having a physical presence.

Nantucket answered 3/1, 2018 at 9:34 Comment(0)
A
2

I think they are using it in it's broadest meaning
Entity: something having real or distinct existence; a thing, esp when considered as independent of other things
So an Entity can be instance of class and types+members Depending on the context.

Lets say you are talking about class definitions if two classes can be "considered as independent"(having different namespaces) they will call it an Entity.

If you are talking about some sort of business logic you might use the "Entity" word for all objects that have the same Id value stored in the in memory property or Database.

Essentially if you can have a function areTheSame(x,y)=>[true,false] and the result of the function for all posible x and y can be false you can call that x or y an entity.

Aimee answered 3/1, 2018 at 11:5 Comment(0)
R
1

An entity in a broader setting is just a "something" that exists.

In the C# ECMA an entity is a placeholder for something that you refer to.

This could be a an instance if you refer to an entity created from a class. Or for example the following section defined a scope the following way:

The scope of a name is the region of program text within which it is possible to refer to the entity declared by the name without qualification of the name.

So to acces a given something (an entity), you need to reference the scope to refer to it. This could be a class, an instance, a static method or else.

Rotberg answered 3/1, 2018 at 9:23 Comment(0)
T
0

Practically speaking and within the realm of CRUD web applications, an entity is simply a class representation of a database table.

Suppose you have a web application consisting of a database with three tables, each having a number of attributes:

  1. Table 1: User

    • Name
    • Surname
    • ID_Number
  2. Table 2: Address

    • Residential_address
    • Postal address
  3. Table 3: Preferences

    • Food
    • Color

If you wanted to use this database within your web application, you would need to create three entities which look like this.

 public class User
 {
    public string Name { get; set; }
    public string Surname { get; set; }
    public string IDNumber { get; set; }
 }

 public class Address
 {
    public string ResidentialAddress{ get; set; }
    public string PostalAddress{ get; set; }
 }

 public class Preferences
 {
    public string Food{ get; set; }
    public string Color{ get; set; }
 }

In a large number of C# web projects, if you deal with databases, your project would likely have a folder called "entities" and it would include classes called entities, just like the examples shown above.

There is quite a bit of qualifying required on the above and it also strongly depends on what framework you use, but the above is the most common practical interpretation on entity.

Tryptophan answered 20/8, 2021 at 4:16 Comment(0)
J
-1

I think this is a common way to explain what an entity is in .NET:

An entity represents a specific object (such as a specific customer or order). Each entity must have a unique entity key within an entity set. An entity set is a collection of instances of a specific entity type. Entity sets (and association sets) are logically grouped in an entity container.

Refer to Microsoft

Jodeejodhpur answered 1/7, 2023 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.