Database and Data Access Flashcards
What is ADO.NET?
ADO.NET is a data access technology in .NET that provides a set of classes for connecting to databases, executing queries, and managing data.
How does ADO.NET manage data access?
ADO.NET uses data providers to connect to various types of data sources. The core data providers are SqlConnection for SQL Server, OleDbConnection for OLE DB, and OracleConnection for Oracle.
Explain the difference between DataSet and DataReader in ADO.NET.
DataSet is an in-memory representation of data that supports relational data, relationships, and multiple tables. DataReader is a forward-only, read-only stream of data that’s more memory-efficient for reading large datasets.
What is Entity Framework (EF)?
Entity Framework is an Object-Relational Mapping (ORM) framework that simplifies database access by allowing you to work with database entities as if they were regular .NET objects.
What are the different approaches for working with EF?
EF supports two approaches: Database-First (where the database schema is generated from the existing database) and Code-First (where the database schema is generated from your C# classes).
What is a SQL JOIN?
A SQL JOIN combines rows from two or more tables based on a related column between them. Common types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
Explain stored procedures in the context of databases.
A stored procedure is a precompiled set of one or more SQL statements that can be executed by calling the procedure’s name. They offer reusability, security, and performance benefits.
What is an ORM?
ORM stands for Object-Relational Mapping. It’s a technique for mapping database tables and relationships to programming language objects, making database interactions more object-oriented.
How does Entity Framework handle lazy loading?
Lazy loading is a technique where related entities are loaded from the database only when accessed for the first time. EF supports lazy loading through proxy objects.
What is the purpose of the DbContext class in Entity Framework?
The DbContext class is the main entry point to the Entity Framework. It represents the session with the database and provides methods to query, insert, update, and delete data.
What is the Entity Framework Core (EF Core)?
EF Core is a lightweight and cross-platform version of Entity Framework, designed for building applications that run on .NET Core and .NET 5+.
How does Entity Framework Core differ from Entity Framework (EF)?
EF Core is a reimagined and modernized version of EF, with improved performance, support for different platforms, and a simplified API. It’s optimized for microservices and cloud-based applications.
What are migrations in Entity Framework?
Migrations are a way to manage database schema changes over time. They allow you to apply changes to the database schema as your model evolves.
What is LINQ to SQL?
LINQ to SQL is a component of ADO.NET that allows you to use LINQ (Language Integrated Query) syntax to query and manipulate SQL Server databases.
Explain the concept of database normalization.
Database normalization is the process of organizing a database’s schema to reduce data redundancy and improve data integrity. It involves breaking down tables into smaller, related tables.
How can you prevent SQL injection when executing raw SQL queries in ADO.NET or Entity Framework?
To prevent SQL injection, use parameterized queries. Parameters ensure that user input is treated as values and not executable code.
What is the purpose of an Object-Relational Mapping (ORM) tool like Entity Framework?
An ORM simplifies the process of interacting with databases by abstracting the details of SQL queries and providing a higher-level, object-oriented interface for database operations.
How can you optimize database performance in Entity Framework applications?
Optimize performance by minimizing the number of database queries, using appropriate indexes, avoiding the N+1 query problem, and using appropriate caching strategies.
Explain the concept of a database transaction.
A database transaction is a sequence of one or more SQL statements executed as a single unit of work. It ensures data integrity by either committing all changes or rolling them back if an error occurs.
What is the difference between an INNER JOIN and a LEFT JOIN?
An INNER JOIN returns only the matching rows from both tables based on the specified condition. A LEFT JOIN returns all rows from the left table and matching rows from the right table, filling in with NULLs where no match is found.