开发者

F# Linq to sql - call stored procedure

I used view here before I was not needed in some parameter, but now I need it and it fails or maybe I'm making something wrong.

here is my try :

member X.CountStatistics ha = 
    <@ linq.IncidentStatistix(ha) @>
    |> query 
    |> Seq.map (fun s -> s.Name, s.Stat)
    |> Array.ofSeq

Parameter got bit type. Linq converted it as Nullable (no idea why nullable) and so I pass value there and it fails with

The following construct was used in query but is not recognised by the F#-to-LINQ query translator:
Call (Some (FieldGet (Some (Value (IncidentStats+ins)), LinqBase.FRIIB linq)),
      System.Data.Linq.ISingleResult`1[LinqBase.IncidentStatistixResult] IncidentStatistix(System.Nullable`1[System.Boolean]),
      [Value (false)])
This is not a valid query expression. Check the specification of permitted queries and consider开发者_如何学运维 moving some of the query out of the quotation

what am I doing wrong ?


When calling stored procedure (exposed as a method of DataContext), you don't need to wrap the call inside quotations. It can be executed as a normal method (without query):

member X.CountStatistics ha = 
    linq.IncidentStatistix(ha)
    |> Seq.map (fun s -> s.Name, s.Stat)    
    |> Array.ofSeq

You can also use sequence comprehensions seq { ... } or array comprehensions [| ... |] to make the additional processing - maybe - a bit nicer:

member X.CountStatistics ha = 
    [| for s in linq.IncidentStatistix(ha) -> s.Name, s.Stat |]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜