扁平化 LINQ 查询 SelectMany 结果

Flattern LINQ Query SelectMany Result

我看过类似的问题,但是none一样。我有一些复杂的查询,例如:

        var myResults = await context.Loot
            .Include(x => x.LootTable)
            .ThenInclude(x => x.Notes)
            .SelectMany(t => t.LootTable, (reward, x) => reward.LootTable
                .SelectMany(y => y.Notes, (l, x) => new MyStuff(

                    reward.rewardId,
                    l.lId,
                    x.Date,
                    "Red",
                    reward.Type,
                    l.Title,
                    x.DisplayName,
                    "Weapon",
                    x.Message
                ))).ToListAsync();

我正在尝试获取 MyStuff 对象列表,但上面给出了多个 MyStuff 列表。如何将其展平为一个列表?

没有内置的 "Flatten" 运算符,但您可以执行 .SelectMany(x => x) 来展平结果:

var myResults = ...;
var flattenedResults = myResults.SelectMany(x => x);