Junior — Middle
Have you had practical experience creating queries that combine data from multiple tables or sources?
sobes.tech AI
Answer from AI
Yes, in C# practice, it is common to create queries that combine data from multiple tables or sources. Usually, LINQ or SQL queries through ORM (e.g., Entity Framework) are used.
Example of joining two tables using LINQ:
var query = from order in dbContext.Orders
join customer in dbContext.Customers
on order.CustomerId equals customer.Id
select new {
OrderId = order.Id,
CustomerName = customer.Name,
order.OrderDate
};
foreach (var item in query) {
Console.WriteLine($"Order {item.OrderId} from {item.CustomerName} on {item.OrderDate}");
}
It is also possible to combine data from different sources, for example, from a database and an external API, by preloading data and using LINQ to Objects for merging.
This allows flexible construction of complex queries and obtaining aggregated or combined data.