c# - RavenDB load related data not working -
the following code throws exception on session.load<employee>(order.employee)
, have no problem querying employee directly.
static void loadrelateddata() { using (var session = mystore.opensession()) { var employeefromquery = session.query<employee>().firstordefault(); //works var order = session.include<order>(o => o.employee).load("orders/819"); //works var employeerelatedtoorder = session.load<employee>(order.employee); //exception var dynamicrelatedtoorder = session.load<dynamic>(order.employee); //works } } private static idocumentstore mystore = new documentstore() { url = "http://localhost:4444/ravendb", defaultdatabase = "hello" }.initialize();
the exception -
an unhandled exception of type 'system.invalidcastexception' occurred in raven.client.lightweight.dll additional information: unable cast object of type 'raven.abstractions.linq.dynamicjsonobject' type 'ravenapp.employee'
.
i'm basing code on http://ravendb.net/docs/article-page/2.5/csharp/client-api/querying/handling-document-relationships
the employee , order data generated raven create sample data task.
as you've used include, order.employee should populated , not require second load.
static void loadrelateddata() { using (var session = mystore.opensession()) { var employeefromquery = session.query<employee>().firstordefault(); var order = session.include<order>(o => o.employee).load("orders/819"); // access them directly, have been resolved var employeerelatedtoorder = order.employee; var dynamicrelatedtoorder = (dynamic)order.employee; } }
Comments
Post a Comment