using System.Collections.Generic;
public static void Main()
var products = new List<Product>()
new Product() { ProductCode = 1, ClientId = 1 },
new Product() { ProductCode = 2, ClientId = 1 },
new Product() { ProductCode = 3, ClientId = 2 },
new Product() { ProductCode = 4, ClientId = 3 }
var clients = new List<Client>()
new Client() { ClientId = 1, ClientName = "Bob" },
new Client() { ClientId = 2, ClientName = "Laura" }
var productClientModels = products
(p, c) => new ProductClientModel
ProductCode = p.ProductCode,
Clients = c.DefaultIfEmpty()
.OrderByDescending(p => p.ProductCode)
foreach (var productClient in productClientModels)
foreach (var client in productClient.Clients)
Console.WriteLine("ProductCode = " + productClient.ProductCode + "; ClientId: " + client?.ClientId + "; Client Name: " + client?.ClientName);
public long ProductCode { get; set; }
public long ClientId { get; set; }
public long ClientId { get; set; }
public string ClientName { get; set; }
public class ProductClientModel
public long ProductCode { get; set; }
public IEnumerable<Client> Clients { get; set; }