LoadAsync with hierarchical Include returns null

46 views
Skip to first unread message

Denis Martinho

unread,
Nov 25, 2016, 6:30:08 AM11/25/16
to RavenDB - 2nd generation document database
From SO : http://stackoverflow.com/questions/40785126/ravendb-loadasync-with-include-returns-null

Hi ! 
Here the SO post : 
I was adding some async calls in my project when i've encountered a problem. The same call between Session and AsyncSession doesn't return my document.
Here the document : 
class Company {
    string Id;
    string Name;
    BusinessUnit BusinessUnit;
} 
class BusinessUnit {
    string Name;
    List<BusinessUnit> BusinessUnits;
    List<Employee> Employees;
} 
class Employee {
    string Position;
    string UserId;
} 
class User {
    string Id;
    string FullName;
} 
User and Company are two collections in my RavenDb. As you can see, we have a tree of business unit in our document Company. So when i want to load a Company, i make this call : 
var company = Session.Include<Employee, User>(x => x.UserId).Load<Company>(companyId); //Working like a charm 

But when i tried to do the same with Async : 
var company = await AsyncSession.Include<Employee, User>(x => x.UserId).LoadAsync<Company>(companyId); //company is null
var company = await AsyncSession.LoadAsync<Company>(companyId); //This is working 
I can't see why it isn't working.
During my searching of answers, i've found a small difference between the implementation of MultiLoaderWithInclude and AsyncMultiLoaderWithInclude. I don't know if my issue can be resolved by these classes.
----------------

Ayende asks for an unit test, you will find one in attachment.
About the versions i was using ravendb 3.5.1 dlls with server build #35179

Thanks for any help :)
Denis
 
LoadAsyncWithHierarchicalIncludesTest.cs

Oren Eini (Ayende Rahien)

unread,
Nov 25, 2016, 4:33:53 PM11/25/16
to ravendb
Thanks for the test, I can confirm the issue.
We'll fix it in the next release, but in the meantime, the root cause is that you are using fields, if you'll use properties, this would work properly.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Denis Martinho

unread,
Nov 28, 2016, 5:49:07 AM11/28/16
to RavenDB - 2nd generation document database
Yep i fixed that. Thanks !
I found another issue : you will find a test in attachment.

This time when i try to use LoadAsync with Includes, the document is not returned when i use the ValueType implementation. But the LoadAsync without includes is working.


To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
LoadAsyncValueTypeWithIncludes.cs

Grisha Kotler

unread,
Nov 28, 2016, 7:21:03 AM11/28/16
to rav...@googlegroups.com
var returnedCompany = await asyncSession.Include<Company, User>(x => x.BusinessUnit.Employees.Select(y => y.UserId)).LoadAsync<Company>(companyShortId);

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Grisha Kotler l RavenDB Core Team Developer Mobile: +972-54-586-8647

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/


To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Nov 28, 2016, 7:26:18 AM11/28/16
to ravendb
The issue is that you are doing something very strange:

  var returnedCompany = await asyncSession.Include<Employee, User>(x => x.UserId)
                        .LoadAsync<Company>(companyShortId); //fails  

We are actually trying to load "employees/1" here, not "companies/1", but without that issue (which is fixed), you are doing something broken, I think Grisha's suggestion is better.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Denis Martinho

unread,
Nov 28, 2016, 8:12:23 AM11/28/16
to RavenDB - 2nd generation document database
I understand Grisha's suggestion but there is something missing : I have a tree of BusinessUnit.

For example i can have a tree like that : 
Company
|
|- BusinessUnit 1
|  |- BusinessUnit 1.1
|  |- BusininessUnit 1.2
|
|- BusinessUnit 2
  |- BusinessUnit 2.1
  |- BusinessUnit 2.2
     |- BusinessUnit 2.2.1
Etc. Etc.

With Grisha's suggestion i will only have the employees of BusinessUnit 1 and 2 and not their child.

Oren Eini (Ayende Rahien)

unread,
Nov 28, 2016, 8:38:55 AM11/28/16
to ravendb
You can use Include with Recurse inside a transformer, then:

But note that this is probably a strange model.

Have the employees of the company as a collection, then have them reference the internal business unit they are on.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Denis Martinho

unread,
Nov 28, 2016, 1:01:37 PM11/28/16
to RavenDB - 2nd generation document database
It's because i'm not giving you our class names in the test, so it's maybe a little odd. Sorry ! ^^'
In fact, i want to load a Company then i will load the Users in each BusinessUnit's Employee list that is why i need to include recursively them. 

Do you mean "collection" like : a document collection or a list of employee in company ? 
In any case, i have to set an id to BusinessUnit, right ? 

By the way, i saw the Ayende's commit about the ValueType on LoadAsync. Thanks ! 

Oren Eini (Ayende Rahien)

unread,
Nov 29, 2016, 2:16:46 AM11/29/16
to ravendb
I meant a list inside the document, yes.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
Reply all
Reply to author
Forward
0 new messages