Inner Join Using Lambda (LINQ)

c#, lambda, linq

Solution

Use `GroupJoin`.

var result =
    defaults.GroupJoin(
        get,
        p1 => p1.PermissionName,
        p2 => p2.PermissionName,
        (p1, joined) =>
            new
            {
                PermissionName = p1.PermissionName,
                Permission = joined.Select(e => e.Permission != null)
                                   .SingleOrDefault()
            });

Problem

I am trying to write the following Linq (query style) in Lambda Expression so that I can chain and make my code more compact: ``` var result = from p1 in defaults join p2 in get on p1.PermissionName equals p2.PermissionName into joined select new { PermissionName = p1.PermissionName, Permission = joined.Select(e => e.Permission == null ? false : true) .SingleOrDefault() }; ``` I could only go this far: ``` var result = defaults.Join(get, defaultKey => defaultKey.PermissionName, getKey => getKey.PermissionName, (a, b) => new { PermissionName = a.PermissionName, Permission = b.Permission }); ``` As you can see that the `Join()` extension method does not provide a way to get the `joined` collection. I also searched online but could not find any leads. Please feel free to suggest.

Original source