Entity Framework Flashcards

(10 cards)

1
Q

What is entity framework

A

Object relational mapper. ORM

Maps .net objects to database tables

Generates sql, query via LINQ

Simplify CRUD

Change tracking

“Entity Framework Core maps .NET objects to database tables and handles translating C# operations into SQL commands automatically.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is DbContext

A

Unit of work object

It can change tracking. Query. Save changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Dbset

A

DbSet represents a table in the database.

It lets you query, add, update, and delete records.

Each DbSet is a collection of entities of a specific type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is entity

A

An Entity is a class that maps to a database table.

Each object of the class represents a row in that table.

Entities have properties that map to columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Change tracking

A

Change Tracking monitors entities for changes.

EF remembers what’s added, modified, or deleted.

When you call SaveChanges(), EF applies only those changes to the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Lazy loading

A

Lazy Loading loads related data only when accessed.

EF does not fetch related entities until you use them.

This saves memory but can cause multiple database queries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Eager Loading

A

Eager Loading loads related data immediately with the main entity.

Use Include() to fetch related tables in a single query.

It reduces multiple database calls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explicit loading

A

Explicit Loading manually loads related data after the main entity is fetched.

You call methods like Load() on a DbSet or navigation property.

It gives control over when data is fetched.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Primary key

A

A Primary Key uniquely identifies each entity in a table. EF requires a key to track and update records. It is usually a property named Id or [ClassName]Id.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Foreign key

A

Question: What is Foreign Key in Entity Framework?

Answer: A Foreign Key links two tables. It stores the primary key of another table. EF uses it to establish relationships between entities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly