I want to create a query in neo4jclient for this cypher query:
MATCH (price:Item)-->(item:Item)
WHERE (item.Id = 2)
WITH item, max(price.Timestamp) AS maxDate
MATCH (price:Item)-->(item:Item)
WHERE (price.Timestamp = maxDate)
RETURN price
I already came up with this piece of code:
_graphClient.Cypher
.Match("(price:Price)-->(item:Item)")
.Where((Item item) => item.Id == 2)
.With((price, item) => new
{
item,
maxDate = Return.As<DateTimeOffset>("max(price.Timestamp)")
})
.Match("(price:Price)-->(item:Item)")
.Where((Price price) => price.Timestamp == Return.As<DateTimeOffset>("maxDate"))
.Return(price=> price.As<Price>())
but this returns the maxDate alias in qoutes:
MATCH (price:Item)-->(item:Item)
WHERE (item.Id = 2)
WITH item, max(price.Timestamp) AS maxDate
MATCH (price:Item)-->(item:Item)
WHERE (price.Timestamp = "maxDate") <--
RETURN price
What is the correct way to do this?
Code wise the Return.As
statements are used to Help Neo4jClient
know what to parse the results as (when used in a Return
statement) and With
is treated in the same way.
When they're used, they output the Cypher
you see (so "max.Timestamp as maxDate"
), and Return.As
will always output that style of response :/
The only way I know of to get the Where
the way you want is via Where("price.Timetamp = maxDate")
, using the string overload.