Entity Framework Core / SQLite: GroupJoin after Join “flattens” results

*爱你&永不变心* 提交于 2019-12-01 07:32:38

问题


Using Entity Framework Core 2.1 and an SQLite database, I get different behaviour from a LINQ GroupJoin if I use it after another Join. It is not clear if this is a bug or if there is something I am overlooking.

I have created a minimal VS2017 project to reproduce this, which can be found here:
https://gitlab.com/haddoncd/EntityFrameworkGroupJoinIssue

In this example, I get one object for each row in the Blog table, each containing multiple PostTitles:

db.Blogs
    .GroupJoin(
        db.Posts,
        s => s.BlogId,
        p => p.BlogId,
        (s, ps) => new
        {
            s.BlogId,
            s.BlogTitle,
            PostTitles = ps.Select(p => p.PostTitle),
        }
    )
    .OrderBy(x => x.BlogId))

But in this example, the results are "flattened" - I get one object for each Blog-Post pair like you would from a conventional SQL outer join:

db.Subscriptions
    .Join(
        db.Blogs,
        s => s.BlogId,
        b => b.BlogId,
        (s, b) => new
        {
            s.SubscriptionId,
            b.BlogId,
            b.BlogTitle,
        }
    )
    .GroupJoin(
        db.Posts,
        x => x.BlogId,
        p => p.BlogId,
        (x, ps) => new
        {
            x.SubscriptionId,
            x.BlogTitle,
            PostTitles = ps.Select(p => p.PostTitle),
        }
    )
    .OrderBy(x => x.SubscriptionId))

来源:https://stackoverflow.com/questions/52246852/entity-framework-core-sqlite-groupjoin-after-join-flattens-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!