CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var loc1 = new Location(){
Id = 1,
Name = "First location"
};
var loc2 = new Location(){
Id = 2,
Name = "Second location"
};
var locList = new List<Location>(){
loc1, loc2
};
var saleT1 = new SaleTransaction(){
Id = 1,
LocationId = 1,
Name = "First SaleT"
};
var saleT2 = new SaleTransaction(){
Id = 2,
LocationId = 2,
Name = "Second SaleT"
};
var saleT3 = new SaleTransaction(){
Id = 3,
LocationId = 1,
Name = "Third SaleT"
};
var saleList = new List<SaleTransaction>(){
saleT1, saleT2, saleT3
};
Console.WriteLine("Join on locationId = 2");
var locId2List = saleList.Join(locList, s => s.LocationId, l => l.Id, (s, l) => new {s.Id, s.Name, s.LocationId, locationName = l.Name})
.Where(l => l.LocationId == 2);
foreach(var item in locId2List){
Console.WriteLine("\t" + item.Id + " " + item.Name + " " + item.LocationId + " " + item.locationName + "\n");
}
}
}
public class SaleTransaction
{
public int Id {get;set;}
public int LocationId {get;set;}
public string Name {get;set;}
}
public class Location
{
public int Id {get;set;}
public string Name {get;set;}
}