4

Resolved

IndexOutOfRangeException in LinqJoinKeyHelper.CreateKeySelectors

description

Effort has been great thus far, however I have encountered an issue when the data structure is somewhat complex and I attempt to 'include' tables with the IQueryable.

The structure works fine when I use a database, but NMemory seems to not like it.

I assume it is line 57 of CreateKeySelectors causing the problem: innerKeyCreator being a different size to outerKeyCreator, which would result in an IndexOutOfRangeException, but Expression Visitors are things I like to avoid getting too deep into, unless it's one I have built myself!

Now, I am using inheritance in my database - just a little - the structure is in the attachment. It results in a lot of joins, but this part of the domain is returning single instances of the aggregate root (Consultant), so the cost is not an issue.

Below is the include list that happens on each query. It's not pretty thanks to the one-to-ones but it's bang on data-wise.
  • .Include(s => s.Specialist)
  • .Include(s => s.Specialist.Person)
  • .Include(s => s.Specialist.Person.EmailAddresses)
  • .Include(s => s.Specialist.Person.PhoneNumbers)
  • .Include(s => s.Specialist.Specialties)
  • .Include(s => s.Specialist.Specialties.Select(p => p.SubSpecialties))
  • .Include(s => s.Specialist.Secretaries)
  • .Include(s => s.Specialist.Secretaries.Select(c => c.Person))
  • .Include(s => s.Specialist.Secretaries.Select(c => c.Person.PhoneNumbers))
  • .Include(s => s.Specialist.Secretaries.Select(c => c.Person.EmailAddresses))
There are actually a couple of other many-to-manys hanging off specialist, but they only link to specialist and don't seem to affect the outcome. In fact, it appears to be the relationship between Person.EmailAddresses and Person.PhoneNumbers. If I remove (or comment out) one of each reference, i.e.
  • .Include(s => s.Specialist)
  • .Include(s => s.Specialist.Person)
  • .Include(s => s.Specialist.Person.EmailAddresses)
  • .Include(s => s.Specialist.Specialties)
  • .Include(s => s.Specialist.Specialties.Select(p => p.SubSpecialties))
  • .Include(s => s.Specialist.Secretaries)
  • .Include(s => s.Specialist.Secretaries.Select(c => c.Person))
  • .Include(s => s.Specialist.Secretaries.Select(c => c.Person.PhoneNumbers))
Everything seems to work just fine.

However, it also only seems to be a problem when I am returning multiple entities. When I use SingleOrDefaultAsync() there are no problems, but ToListAsync() results in the error.

file attachments

comments

tamasflamich wrote Mar 20, 2015 at 3:29 PM

Hi!

Thank you for reporting this!

I am afraid that I will fail or have a really hard time reproducing this issue due to the complexity of the scenario. May I ask you to provide me proof of concept code?

Thanks

RobLS wrote Mar 30, 2015 at 7:03 PM

Possible repo of the issue

RobLS wrote Apr 20, 2015 at 1:50 PM

Oh, I just realized my last post didn't make it clear that I had uploaded a possible repo. Tamasflamich, when you get a chance could you please look at the EffortTest.zip file attachment listed above?

rene87 wrote Jul 9, 2015 at 9:00 AM

Hi,
we use NMemory for Unittest on our Testsystem, some off the Unitest fail with an IndexOutOfRangeException.
in this Statement
            var staffing = await context.tblStaffings
                .Include(r => r.tblMitarbeiter.tblVergütung)
                .Include(r => r.tblMitarbeiter.tblEinstufungs)
                .ToListAsync();
The Exception was thrown in LinqJoinKeyHelper line 57. The outerKeyCreator.Length is 3 and the innerKeyCreator.Length is 1

wertzui wrote Aug 13, 2015 at 12:08 PM

I fixed this Bug and submitted a pull request over at github: https://github.com/tamasflamich/nmemory/pull/5
Would be nice if you could merge it and update the Nuget Package.