أسئلة القسم

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

How do you optimize queries in EF Core? صعب
  • Use AsNoTracking() for read-only.
  • Project only needed columns (Select).
  • Use eager loading wisely.
  • Avoid N+1 queries.
  • Use compiled queries for repeated queries.
  • Profile queries with logging/SQL Profiler.
Explain Transactions in SQL Server and how EF Core manages them. صعب
  • A transaction ensures ACID properties.
  • EF Core wraps SaveChanges() in a transaction.
  • For multiple operations:
using var transaction = db.Database.BeginTransaction();
try {
    db.SaveChanges();
    transaction.Commit();
}
catch {
    transaction.Rollback();
}
What are Interceptors in EF Core, and when would you use them? صعب
  • Interceptors = hooks into EF Core lifecycle (command execution, saving, connections).
  • Useful for logging, auditing, multi-tenancy, soft deletes.
How does EF Core support concurrency handling (Optimistic vs Pessimistic concurrency)? صعب
  • Optimistic: Assumes no conflicts, uses row version or timestamp. If conflict -> exception.
  • Pessimistic: Uses locks to prevent conflicts (via transactions).
What are Compiled Queries in EF Core, and why are they useful? صعب
  • EF normally compiles LINQ -> SQL each time.
  • Compiled queries cache the translation for reuse.
  • Improves performance for frequently executed queries.
What is the difference between Table Splitting and Inheritance (TPH, TPT, TPC) in EF Core? صعب
  • Table Splitting: Multiple entities share one table.
  • Inheritance:
    • TPH (Table-per-Hierarchy): All types in one table.
    • TPT (Table-per-Type): Separate table for each class.
    • TPC (Table-per-Concrete Type): Separate table for each concrete type, no joins.
What is the N+1 query problem in EF Core, and how do you solve it? صعب
  • Problem: One query for main entity + one query per related entity.
  • Example: Looping over users and fetching roles separately.
  • Solution: Use Eager Loading (Include) or projection with Select.