0

I have a query where I want only Id and name of the collection back to reduce the network traffic. I am able to get what i want from the database with the following part of the query

ShipToCities = Return.As<IEnumerable<string>>("COLLECT( [shipTo.InternalId, shipTo.Name])")

but the issue is i get back the data like this:

[ [ "IN.KA.MANG", "Mangalore" ], [ "IN.KA.MANG", "Mangalore" ], [ "IN.KA.BANG", "Bangalore" ] ]

but how can I map it to a C# object like

public class CityFound
{
    public string CityId { get; set; }
    public string CityName { get; set; }
}

is there a way to use some converter to achieve this without me having to use some ugly string manipulation myself?

UPDATE 1:

Actually my query is fairly complex and only way to get the data that I can think of is to handcraft the query like below to reduce the :

//selectedLoadQuery below is a complex query based on user selection...

var query = selectedLoadQuery
    .Match("(load)-[:SHIPPED_BY]->(shipper)-[r:HAS_TRANSPORTER]->(transporter)")
    .With("load, transporter, shipper, user, count(DISTINCT r) as MyClients")
    .Match("p=(shipFrom:City)<-[:SHIP_FROM_CITY]-(load)-[:SHIP_TO_CITY]->(shipTo:City)")
    .With("p, load,  shipFrom, shipTo, transporter, MyClients")
    .Return((load, shipFrom, shipTo) => new
    {
        TotalShipments = load.CountDistinct(),
        FromMyClients = Return.As<long>("MyClients"),
        ShipFromCities = Return.As<IEnumerable<string>>("COLLECT( [shipFrom.InternalId, shipFrom.Name])"),
        ShipToCities = Return.As<IEnumerable<string>>("COLLECT( [shipTo.InternalId, shipTo.Name])"),
     });

Regards Kiran

1

1 Answer 1

0

You don't need to get so creative. You're only getting into this issue because you're hand crafting such a complex query that flattens out the structure of the data.

Create a class that describes what's in the node:

public class ShippingDestination
{
    public long InternalId { get; set; }
    public string Name { get; set; }
}

Use this to light up the following syntax in your Return statement:

var cities = graphClient
    .Match(...)
    .Return(shipTo => new {
        Id = shipTo.As<ShippingDestination>().InternalId,
        Name = shipTo.As<ShippingDestination>().Name,
    })
    .Results;
1
  • I have updated my post above to explain the reason why I have to hand craft. I have removed some part of the query to make it easy to understand. I don't want to get more data than needed on the wire to use LINQ to group by, may be that is causing my issues. Do you happen to have any suggestion what I can do?
    – Kiran
    May 21, 2014 at 17:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.