2

I'm having trouble with Entity Framework Plus. I can't seem to get the loading of multiple levels working.

The following query works fine. I get the user back with the expected list of addresses.

var user = _dataContext.Users
                .Where(u => u.UserName == username)
                .IncludeFilter(u => u.Addresses.Where(a => !a.Deactivated.HasValue))
                .SingleOrDefault();

But the following query causes it to fall apart.

var user = _dataContext.Users
                .Where(u => u.UserName == username)
                .IncludeFilter(u => u.Addresses.Where(a => !a.Deactivated.HasValue).Select(a => a.AddressType))
                .SingleOrDefault();

I get the user back, but now my list of Addresses is empty.

I'm using EF6 and EF+ v1.7.14.0

Thanks in advance to anyone who can help.

Cheers Craig

Craig
  • 417
  • 3
  • 12

1 Answers1

2

Arrgh! What a dope! I need to do it in two statements... which makes perfect sense really. I was selecting out the address type and leaving the address behind.

My query needs to be as follows:

var user = _dataContext.Users
                .Where(u => u.UserName == username)
                .IncludeFilter(u => u.Addresses.Where(a => !a.Deactivated.HasValue))
                .IncludeFilter(u => u.Addresses.Where(a => !a.Deactivated.HasValue).Select(a => a.AddressType))
                .SingleOrDefault();

Thanks me. You're a champ!

Craig
  • 417
  • 3
  • 12
  • 1
    Yup, that's, unfortunately, a limitation of the library. The `QueryIncludeOptimized` have the option `QueryIncludeOptimizedManager.AllowIncludeSubPath = true` that do it by itself but it has not been implement yet for `QueryIncludeFilter` yet. – Jonathan Magnan Jan 19 '18 at 14:57