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

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.