我有两个疑问:
member private x.CheckIfUserExistsUsingId(userId:int, context:StoryBoardContext) =
<@ context.Users
|> Seq.exists (fun currentUser -> currentUser.Id = userId) @>
和
member private x.FindUserById(userId:int, context:StoryBoardContext) =
<@ context.Users
|> Seq.filter(fun currentUser -> currentUser.Id = userId)
|> Seq.head @>
我想重构这个,这样两个
fun currentUser -> currentUser.Id = userId
可以是一种方法,例如:
member private x.IfUserIdMatches (userId:int) =
fun (currentUser:User) -> currentUser.Id = userId
然后使用它:
member private x.CheckIfUserExistsUsingId(userId:int, context:StoryBoardContext) =
<@ context.Users
|> Seq.exists (x.IfUserIdMatches (userId)) @>
但我不断收到错误消息:
The following construct was used in query but is not recognised by the F#-to-LINQ query translator...
这让我觉得我对该方法的签名结构很差。作为 F# 的新手,我有点困惑,因为我很肯定这可以在 C# 中使用返回 Func 的方法来完成。但是,我知道由于 F# 使用不同的库来构建 linq 查询,因此存在差异。