public static void AddGetModel7WithModel8FieldAndConnectionFieldDescription(this TestDocumentDbQuery current, QueryBuilderFactory queryBuilderFactory) { // Find Model7 coming from Model8 queryBuilderFactory.Create <Model7>(current, "GetModel7WithModel8FieldAndConnectionFieldDescription", "Get Model7 With Model8 Field And Connection Field Description") .WithParameterBuilder() .BeginQuery <Model8>() // Use field from Model8 as a starting point to search from. .WithProperty(x => x.Field) .BuildQueryResult(ctx => { ctx.Items["model8IdList"] = ctx.GetQueryResults <Model8>().Select(x => (object)x.Id).ToList(); }) .WithConnectionEdgeBuilder <Model7ToModel8>() // Now, we match Model7ToModel8's DestinationId with Model8 Id. .WithDestinationIdFromSource(ctx => { return((List <object>)ctx.Items["model8IdList"]); }) .WithProperty(x => x.FieldDescription) .BuildConnectionEdgeParameters(ctx => { ctx.Items["model7IdList"] = ctx.GetQueryResults <Model7ToModel8>().Select(x => x.Id) .Distinct() .Select(x => (object)x).ToList(); }) .ThenWithQuery <Model7>() .WithPropertyFromSource(x => x.Id, ctx => { return((List <object>)ctx.Items["model7IdList"]); }) .BuildQueryResult(ctx => { }) .BuildQuery() .BuildWithListResult(); }
public static void AddGetModel7FromConnectionEdge(this TestDocumentDbQuery current, QueryBuilderFactory queryBuilderFactory) { // This query is really only meant to demostrate the ability to query for connection edges from the node itself // even if user's query does not include the connection model. This is achieved via WithSourceIdFromSource. // Typically, the use case may be that the user is performing a search (which doesn't use connection model). This // means as a developer, you may want to query the connection edge yourself to figure out the child node hanging on // the connection model. queryBuilderFactory.Create <Model7>(current, "GetModel7FromConnectionEdge") .WithParameterBuilder() .BeginQuery <Model7>().WithProperty(x => x.Id) .BuildQueryResult(ctx => { ctx.Items["idList"] = ctx.GetQueryResults <Model7>().Select(x => (object)x.Id).ToList(); }) .WithConnectionEdgeBuilder <Model7ToModel8>() .WithSourceIdFromSource <Model7>(x => (List <object>)x.Items["idList"]) .BuildConnectionEdgeParameters(ctx => { var connectionEdges = ctx.GetResults <ConnectionEdge>(); }) .BuildQuery() .BuildWithSingleResult(); }