Entity Framework Core Interview Question #7
What is an entity in EF Core?
EF Core Fundamentals & DbContext Junior Beginner
Quick Interview Answer
An entity is a .NET object type that EF Core includes in its model and can map to database data. A typical entity has scalar properties, a primary key, and optional navigation properties describing relationships.
Detailed Explanation
An entity is a .NET object type that EF Core includes in its model and can map to database data. A typical entity has scalar properties, a primary key, and optional navigation properties describing relationships.
Entities can be discovered through DbSet properties, relationship configuration, or explicit model configuration.
Entity classes should represent meaningful application data. Public persistence entities should not automatically be used as web input models because that can expose fields that clients should not be allowed to modify.
Code Example
public class Customer
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public ICollection<Order> Orders { get; set; } = new List<Order>();
}