What is an Entity in Entity Framework Core?

Beginner

Answer

An Entity is a class that represents a table in the database. Each instance of an entity corresponds to a row in the table.

public class Product
{
    public int Id { get; set; }           // Primary key
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int CategoryId { get; set; }
    // Navigation property
    public Category Category { get; set; }
}

Requirements for an entity:

  • Must be a reference type (class)
  • Must have a parameterless constructor
  • Should have a primary key property
  • Properties must have public getters and setters (or protected setters)