Linq多集合连接

  class Program
    {
        static void Main(string[] args)
        {
            List<Test1> list1 = new List<Test1>();
            List<Test2> list2 = new List<Test2>();
            List<Test3> list3 = new List<Test3>();

            list1.Add(new Test1()
            {
                 Age1 = 30,
                  Name = "30Name"
            });
            list1.Add(new Test1()
            {
                Age1 = 40,
                Name = "30Name"
            });

            list2.Add(new Test2()
            {
                Age2 = 30,
                Name = "30Name2"
            });
            list2.Add(new Test2()
            {
                Age2 = 40,
                Name = "30Name2"
            });

            list3.Add(new Test3()
            {
                Age3 = 30,
                Name = "30Name3"
            });
            list3.Add(new Test3()
            {
                Age3 = 40,
                Name = "30Name3"
            });

            var end = (from a in list1
                       join b in list2 on a.Age1 equals b.Age2
                       join cc in list3 on a.Age1 equals cc.Age3
                       select new Test3()
                       {
                           Age3 = a.Age1,
                           Name1 = a.Name,
                           Name2 = b.Name,
                           Name3 = cc.Name,

                       }).ToList();
            Console.WriteLine( 0 );
        }
    }



public class Test1
{
public int Age1 { get; set; }
public string Name { get; set; }
}
public class Test2
{
public int Age2 { get; set; }
public string Name { get; set; }
}
public class Test3
{
public int Age3 { get; set; }
public string Name { get; set; }

public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
}

  

posted @ 2021-10-15 15:49  艾特-天空之海  阅读(32)  评论(0编辑  收藏  举报