我有一个查询,我只想回收ID和名称,以减少网络流量。我可以通过查询的以下部分从数据库中获得我想要的东西
ShipToCities = Return.As<IEnumerable<string>>("COLLECT( [shipTo.InternalId, shipTo.Name])")
但问题是我收回这样的数据:
[ [ "IN.KA.MANG", "Mangalore" ], [ "IN.KA.MANG", "Mangalore" ], [ "IN.KA.BANG", "Bangalore" ] ]
但我怎样才能将它映射到C#对象,如
public class CityFound
{
public string CityId { get; set; }
public string CityName { get; set; }
}
有没有办法使用一些转换器实现这一点,而我自己不必使用一些丑陋的字符串操作?
更新1:
实际上我的查询相当复杂,只有获取我能想到的数据的方法是手工编写下面的查询以减少:
//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])"),
});
此致 基兰
答案 0 :(得分:0)
你不需要那么有创意。您只是遇到了这个问题,因为您正在手工制作这样一个复杂的查询,以平衡数据的结构。
创建一个描述节点内容的类:
public class ShippingDestination
{
public long InternalId { get; set; }
public string Name { get; set; }
}
使用此选项可在Return
语句中点亮以下语法:
var cities = graphClient
.Match(...)
.Return(shipTo => new {
Id = shipTo.As<ShippingDestination>().InternalId,
Name = shipTo.As<ShippingDestination>().Name,
})
.Results;