أسئلة القسم

تدرب على أسئلة المقابلات في هذا القسم. اكتب إجابتك، قم بتقييمها، أو اضغط على "عرض الإجابة" بعد التفكير.

Explain Entity Framework Core and its advantages. سهل

Entity Framework Core (EF Core) is Microsoft’s modern Object-Relational Mapper (ORM) for .NET. It lets you work with databases using C# classes instead of SQL directly.

Advantages:

  • Cross-platform (works with .NET Core)
  • Supports LINQ queries
  • Change tracking and relationship management
  • Migrations for schema evolution
  • Works with many databases (SQL Server, PostgreSQL, MySQL, SQLite)
What are Migrations in EF Core? سهل

A way to evolve the database schema as your models change. They keep C# models and DB schema in sync.

Example commands:

  • Add-Migration InitialCreate
  • Update-Database
What is different between Code First and Db First? سهل
Approach Code First Database First
Start point Define C# classes (models) Start from existing database schema
Schema creation EF creates/updates DB schema via migrations EF generates models from DB
Best for Greenfield projects (new DB) Legacy/existing databases
What is Database Seeding? سهل

Seeding = pre-populating the database with initial/static data. Done in OnModelCreating using .HasData().

Example:

modelBuilder.Entity<Role>().HasData(new Role { Id = 1, Name = "Admin" });
What is the difference between SaveChanges() and SaveChangesAsync()? سهل
  • SaveChanges(): Synchronous, blocks the thread until DB operation finishes.
  • SaveChangesAsync(): Asynchronous, does not block, returns a Task. Use SaveChangesAsync() in web apps for better scalability.