NoI*_*his 6 f# neo4j neo4jclient
鉴于此查询(从这里)
let pAfollowers =
client.Cypher
.Match("n<-[:follows]-e")
.Where(fun n -> n.Twitter = "tA")
.Return<Person>("e")
.Results
.Select(fun x -> x.Name)
Run Code Online (Sandbox Code Playgroud)
我想调整它并让它返回打包在一起的多个值.不确定类型的外观:
let pAfollowers =
client.Cypher
.Match("n<-[r:follows]-e")
.Where(fun n -> n.Twitter = "tA")
.Return<???>("n, r, e")
Run Code Online (Sandbox Code Playgroud)
其次,我想知道是否有可能在a之后有一个return语句CreateUnique.我试图调整此查询:
let knows target (details : Knows) source =
client.Cypher
.Match("(s:Person)", "(t:Person)")
.Where(fun s -> s.Twitter = source.Twitter)
.AndWhere(fun t -> t.Twitter = target.Twitter)
.CreateUnique("s-[:knows {knowsData}]->t")
.WithParam("knowsData", details)
.ExecuteWithoutResults()
Run Code Online (Sandbox Code Playgroud)
让它回归s,t而且details.
好吧,好消息/坏消息 - 尽管在实践中,好消息与坏消息是调和的:(
先说好:
您可以在 CreateUnique 之后返回,如下所示:
.CreateUnique("s-[:Knows {knowsData}]-t")
.WithParam("knowsData", details)
.Returns<???>( "s,t" )
.Results;
Run Code Online (Sandbox Code Playgroud)
坏消息:
坏消息是您可能无法在 F# 中做到这一点。Neo4jClient要求您使用对象初始值设定项或匿名类型来转换数据,因此您可以尝试以下操作:
type FollowingResults = { Follower : Person; Followed : Person;}
let createExpression quotationExpression = LeafExpressionConverter.QuotationToLambdaExpression quotationExpression
let pAfollowers =
client.Cypher
.Match("n<-[:follows]-e")
.Where(fun n -> n.Twitter = "tA")
.Return(createExpression <@ Func<ICypherResultItem, ICypherResultItem, FollowingResults>(fun (e : Cypher.ICypherResultItem) (n : Cypher.ICypherResultItem) -> {Follower = e.As<Person>(); Followed = n.As<Person>()}) @>)
.Results
.Select(fun x -> x)
for follower in pAfollowers do
printfn "%s followed %s" follower.Follower.Name follower.Followed.Name
Run Code Online (Sandbox Code Playgroud)
F# 编译器对此不会有任何问题。但是,Neo4jClient将引发参数异常并显示以下消息:
该表达式必须构造为对象初始值设定项(例如:n => new MyResultType { Foo = n.Bar })、匿名类型初始值设定项(例如:n => new { Foo = n.Bar })、方法调用(例如:n => n.Count()),或成员访问器(例如:n => n.As().Bar)。您不能提供代码块(例如:n => { var a = n + 1; return a; })或使用带参数的构造函数(例如:n => new Foo(n))。
问题是,F#没有对象初始值设定项,也没有匿名类型,您可能会与 F# 的内容争论很长时间却一事无成,因为 C# 无法识别 F# 初始化。