FLinq SQL "IN clause"

I am trying to easily create "IN CLause" via f # linq - but it seems I cannot get it. I tried two options:

Iterate over a list of days as part of a sequence expression:

let getHistoricalQuotes (securityId:int) (days:string seq) =
    let results = 
        Query.query <@ seq { 
            for day in days do
                for sq in db.SecurityQuote do
                    if sq.SecurityId =?! securityId && sq.Day = day then
                        yield sq ;
        } @> 

And the List.exists clause:

let getHistoricalQuotes (securityId:int) (days:string list) =
    let results = 
        Query.query <@ seq { 
            for sq in db.SecurityQuote do
                if sq.SecurityId =?! securityId && List.exists (fun d -> d = sq.Day) days then
                    yield sq ;
        } @> 

    results

Both give me:

base {System.SystemException} = {"The method 'Microsoft.FSharp.Core.FSharpFunc 2[System.String,System.Boolean] ToFSharpFunc[String,Boolean](System.Converter2 [System.String, System.Boolean])' does not support SQL translation." }

as always, thanks for the help in advance ...


rewritten:

let getHistoricalQuotes (securityId:int) (days:string list) =
    let results = 
        Query.query <@ 
            Query.join
                db.SecurityQuote 
                days
                (fun sq -> if(sq.SecurityId =?! securityId) then sq.Day else "") 
                (fun d -> d) 
                (fun sq d -> sq)  @> 

    results

and got this exception:

System.Exception
= , F # -to-LINQ: ([ "2010/01/04", "2010/02/01"; "2010/03/01"; "2010/04/01"; "2010/05/03"; "2010/06/01"; "2010/07/01"; "2010/08/02"; "2010/09/01"; "2010/10/01"; "2010/11/01"; "2010/12/01"; "2010/01/29"; "2010/02/26"; "2010/03/31"; "2010/04/30"; "2010/05/31"; "2010/06/30"; "2010/07/30"; "2010/08/31"; "2010/09/30"; "2010/10/29"; "2010/11/30"; "2010/12/31" ]) .

- (selext * from Historicalquote)


, , , , , .

let getHistoricalQuotes (securityId:int) (days:string list) =
    let getQuote (day) =  
        Query.query <@ seq { 
            for sq in db.SecurityQuote do
                if sq.SecurityId =?! securityId && sq.Day = day then
                    yield sq ;
        } @> |> Seq.head

    List.map (fun day -> getQuote day) days

let getHistoricalQuotes (securityId:int) (days:string list) =
    let results =  
        Query.query <@ seq { 
            for sq in db.SecurityQuote do
                if sq.SecurityId =?! securityId && days.Contains(sq.Day) then
                    yield sq ;
        } @> 
    results

1 , ""


- ( ):

let getHistoricalQuotes (securityId:int) (days:string array) =
    let results =  
        Query.query <@ seq { 
            for sq in db.SecurityQuote do
                if sq.SecurityId =?! securityId && days.Contains(sq.Day) then
                    yield sq ;
        } @> 
    results

, System.Linq. - ,

+3
1

Linq, , :

days.Contains(day)
+2

Source: https://habr.com/ru/post/1773303/


All Articles