gpt4 book ai didi

C# 将两个集合连接在一起

转载 作者:太空宇宙 更新时间:2023-11-03 20:57:13 24 4
gpt4 key购买 nike

C# 中的全新尝试将两个集合连接在一起,最终结果将提供来自两个集合的所有数据。现在代码只返回匹配的文档。谢谢。

  //Collections   IQueryable collection1 = database.GetCollection("MainData").AsQueryable();   IQueryable collection2 = database.GetCollection("SecondaryData").AsQueryable();           var result = collection2.Join(collection1, a => a.ID, b => b.ID, (a, b) => new { a, b })                .ToList()                .Select(s => new ViewModel.Customer()                {                    ID = s.b.ID,                    FirstName = s.b.FirstName                    LastName = s.b.LastName                }).ToList();            return result;

最佳答案

You could use Concat which will return the items from the first collection followed by the items from the second collection:

var combined = collection1.Concat(collection2);

Or you could use Union which will return distinct values from both collections:

var combined = collection1.Union(collection2);

关于C# 将两个集合连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49261148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com