أسئلة القسم
تدرب على أسئلة المقابلات في هذا القسم. اكتب إجابتك، قم بتقييمها، أو اضغط على "عرض الإجابة" بعد التفكير.
What is Tracking in EF Core? متوسط
Change Tracking means EF keeps track of entity states (Added, Modified, Deleted, Unchanged). Helps generate the correct SQL for SaveChanges().
What is the difference between IEnumerable and IQueryable in EF Core? متوسط
- IEnumerable: Executes query in memory after fetching data.
- IQueryable: Translates query to SQL and executes in DB.
Example:
// IEnumerable -> loads all then filters in memory
db.Users.AsEnumerable().Where(u => u.Age > 18);
// IQueryable -> SQL WHERE clause executed on server
db.Users.Where(u => u.Age > 18);
Explain eager loading vs lazy loading in EF. متوسط
- Eager Loading: Related entities loaded immediately (Include()).
- Lazy Loading: Related entities loaded when accessed (requires proxies).
How would you handle migrations in EF Core? متوسط
- Add-Migration
– create migration - Update-Database – apply migration
- Remove-Migration – undo last migration Use version control to keep migrations in sync across environments.
What are Shadow Properties in EF Core? متوسط
Properties not defined in your C# entity, but tracked by EF. Useful for metadata (e.g., CreatedDate, LastModifiedBy).
What are Global Query Filters in EF Core? متوسط
Filters applied automatically to all queries for an entity. Example: Soft delete or multi-tenancy.
Example:
modelBuilder.Entity<User>().HasQueryFilter(u => !u.IsDeleted);
What is the difference between Value Objects and Entities in EF Core? متوسط
- Entity: Has identity (Id), tracked by EF.
- Value Object: No identity, compared by value.
What is the difference between AsNoTracking() and normal queries in EF Core? متوسط
- Normal queries: Entities tracked by EF.
- AsNoTracking(): Returns entities not tracked, better for read-only queries.
What are Owned Entity Types in EF Core? متوسط
Complex types owned by another entity, no separate table by default.
Example:
modelBuilder.Entity<User>().OwnsOne(u => u.Address);
Explain how Change Tracking works in EF Core. متوسط
- EF assigns states: Added, Modified, Deleted, Unchanged.
- Uses snapshots or proxies to detect changes.
- On SaveChanges(), generates SQL based on state.
Explain how EF Core translates LINQ queries to SQL. متوسط
- LINQ -> Expression Tree -> SQL via EF Core provider.
Example:
db.Users.Where(u => u.Age > 18);
becomes
SELECT * FROM Users WHERE Age > 18;
How can you log SQL queries generated by EF Core? متوسط
Using ILogger or LogTo:
optionsBuilder.LogTo(Console.WriteLine);
What are Keyless Entities (Query Types) in EF Core? متوسط
- Entities without primary keys, used for read-only queries (e.g., views, raw SQL).
- Defined with .HasNoKey().