只是做一些简单的像这样:F#类型inferrence问题与LINQ和可能的实体框架
context.Users.Any(fun currentUser -> currentUser.UserName = userName)
如果上下文是一个实体的框架范围内。现在,当我将鼠标悬停在“currentUser”上时,它知道它是用户类型。不过,我得到:
根据 之前的信息在此程序点上查找不确定类型的对象。在这个程序点之前可能需要一个类型注释来约束对象的类型。这可能会允许解析 查找。
现在我知道我可以做到这一点:
context.Users.Any(fun (currentUser:User) -> currentUser.UserName = userName)
,但似乎真的很傻,因为C#可以很容易地推断出与类型:
context.Users.Any(currentUser => currentUser.UserName = userName)
全面的方法是这样的:
let FindAndRemoveUser(userName:String, context:StoryBoardContext) =
if context.Users.Any(fun currentUser-> currentUser.UserName = userName) then
let foundUser = context.Users.Where(fun innerUser -> innerUser.UserName = userName).First()
context.Users.DeleteObject(foundUser)
context.SaveAll() |> ignore
我错了,认为F#应该处理类型inf还是比C#好?
不错......真的很高兴我问了这个问题。我一直想要一个理由来看看这个动力包,现在看起来毫无疑问。 –
@程序员:直到F#3.0(希望)。 : - ] – ildjarn