gpt4 book ai didi

F# - 具有多个返回值的密码查询

转载 作者:行者123 更新时间:2023-12-04 15:22:44 25 4
gpt4 key购买 nike

鉴于此查询(来自 here )

  let pAfollowers =
client.Cypher
.Match("n<-[:follows]-e")
.Where(fun n -> n.Twitter = "tA")
.Return<Person>("e")
.Results
.Select(fun x -> x.Name)

我想调整它并让它返回打包在一起的多个值。
不确定类型应该如何显示:

let pAfollowers =
client.Cypher
.Match("n<-[r:follows]-e")
.Where(fun n -> n.Twitter = "tA")
.Return<???>("n, r, e")

其次,我想知道是否有可能在 CreateUnique 之后有一个 return 语句。 .
我正在尝试调整此查询:

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()

让它返回 s , tdetails .

最佳答案

好的,好消息/坏消息 - 尽管在实践中好与坏相结合:(

先说好:

您可以在 CreateUnique 之后返回,例如:

.CreateUnique("s-[:Knows {knowsData}]-t")
.WithParam("knowsData", details)
.Returns<???>( "s,t" )
.Results;

坏消息:

坏消息是您可能无法在 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

F# 编译器对此完全没有问题。然而, Neo4jClient将抛出带有以下消息的 Argument 异常:

The expression must be constructed as either an object initializer (for example: n => new MyResultType { Foo = n.Bar }), an anonymous type initializer (for example: n => new { Foo = n.Bar }), a method call (for example: n => n.Count()), or a member accessor (for example: n => n.As().Bar). You cannot supply blocks of code (for example: n => { var a = n + 1; return a; }) or use constructors with arguments (for example: n => new Foo(n)).



问题是,F# 没有对象初始值设定项,也没有匿名类型,您可以与 F# 的东西纠缠多年而无处可去,因为 C# 无法识别 F# 初始化。

关于F# - 具有多个返回值的密码查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com