Hi, There is a bug with GroupJoin on nullable key that leads to invalid grouping. If I try to GroupJoin EntityA with EntityB by nullable field, the join key of EntityA without matching keys of EntityB starts matching all null keys from EntityB Code reproducing the issue:

namespace Sample
{
    using System;
    using System.Linq;
    using Xtensive.Orm;
    using Xtensive.Orm.Configuration;

    [HierarchyRoot]
    public class SimpleEntity : Entity
    {
        [Field][Key] public int Id { get; set; }

        [Field] public string Name { get; set; }
    }

    [HierarchyRoot]
    public class EntityWithLink : Entity
    {
        [Field][Key] public int Id { get; set; }

        [Field] public SimpleEntity Link { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var dc = new DomainConfiguration("sqlserver", "Data Source=.; Initial Catalog=DO40-Tests;Connection Timeout=300;Integrated Security = true;Max pool size=10");

            dc.Types.Register(typeof(Program).Assembly);
            dc.UpgradeMode = DomainUpgradeMode.Recreate;

            var sessionConfiguration = new SessionConfiguration(SessionOptions.AutoActivation | SessionOptions.ServerProfile);

            using (var domain = Domain.Build(dc))
            {
                using (var session = domain.OpenSession(sessionConfiguration))
                using (session.Activate())
                using (session.OpenTransaction(TransactionOpenMode.New))
                {
                    var withLink = new SimpleEntity { Name = "WithLink" };
                    var withoutLink1 = new SimpleEntity { Name = "WithoutLink1" };
                    var withoutLink2 = new SimpleEntity { Name = "WithoutLink2" };

                    new EntityWithLink { Link = withLink, };
                    new EntityWithLink { Link = withLink, };
                    new EntityWithLink { Link = null, };
                    new EntityWithLink { Link = null, };
                    new EntityWithLink { Link = null, };

                    var counts = Query.All<SimpleEntity>() // .AsEnumerable()
                        .GroupJoin(Query.All<EntityWithLink>(),
                            simpleEntity => simpleEntity,
                            entityWithLink => entityWithLink.Link,
                            (simpleEntity, links) => new
                            {
                                simpleEntity.Name,
                                Count = links.Count()
                            })
                        .ToArray();

                    foreach (var count in counts)
                    {
                        Console.WriteLine($"{count.Name} - {count.Count}");
                    }
                }
            }
        }
    }
}

Output of the sample:

WithLink - 2
WithoutLink1 - 3
WithoutLink2 - 3

The problem has appeared in 5.0.18 version (5.0.17 is ok)

asked Apr 05 '19 at 05:55

Platonov's gravatar image

Platonov
5778

edited Apr 05 '19 at 06:34


One Answer:

Hello Platonov,

It seems we broke something :) I will check what went wrong and in which version exactly. Thank you for the report.

Update: Figured it out. Changes in 5.0.18 Beta 2 related to GroupBy() affected GroupJoin(). Fixed it in developing branch.

answered Apr 05 '19 at 08:24

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

edited Apr 08 '19 at 11:09

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×1

Asked: Apr 05 '19 at 05:55

Seen: 3,856 times

Last updated: Apr 08 '19 at 11:09

Related questions

powered by OSQA