I have a class called Product that contains some properties like Id (as Guid) and Messages (as List), and a Message class that also contains Id and other properties. I have all messages in Message table and all products in product table. After getting data of both tables, I want to join them regarding on Id property. If I use the below code as it is linear search the performance is terrible.
foreach (Product product in products)
product.Messages = messages.Where(n => n.Id == product.Id).ToList();
Are there any other ways to do it faster?
Thanks