Sobes.tech
Junior — Middle

Tell about a situation where you used a relational database in practice.

sobes.tech AI

Answer from AI

In one of my projects using C#, I utilized a relational SQL Server database to store information about users and their orders. For example, I had a Users table with fields Id, Name, Email, and an Orders table with fields OrderId, UserId, OrderDate. A foreign key UserId in the Orders table was used to easily retrieve all orders for a specific user through JOIN queries.

An example query in C# using Entity Framework:

var userOrders = context.Users
    .Where(u => u.Id == userId)
    .Select(u => new {
        u.Name,
        Orders = u.Orders.Select(o => new { o.OrderId, o.OrderDate })
    })
    .FirstOrDefault();

This approach allowed efficient data management, ensured integrity, and leveraged the powerful capabilities of SQL for selection and aggregation.