F# 3 Linq Query expressions

334 views
Skip to first unread message

Bohdan Szymanik

unread,
Apr 16, 2012, 8:41:53 PM4/16/12
to ravendb
Just been trying the query expression syntax in F# 3 - but it doesn't
seem to work yet? I'm guessing that's the case. I tried something like
this on a movie collection with an Artists index:

query { for artist in session.Query<Movie>("Artists") do
select artist
}

But I get:
System.IO.FileNotFoundException: Could not load file or assembly
'Raven.Client.Lightweight, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=37f41c7f99471593' or one of its dependencies. The
system cannot find the file specified.
File name: 'Raven.Client.Lightweight, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=37f41c7f99471593'
etc etc ...

Anyhow, enjoying ravendb irrespective.
Bohdan

Oren Eini (Ayende Rahien)

unread,
Apr 17, 2012, 3:14:34 AM4/17/12
to rav...@googlegroups.com
Are you sure that you are using the same versions of the bundles?

Oren Eini (Ayende Rahien)

unread,
Apr 17, 2012, 3:14:45 AM4/17/12
to rav...@googlegroups.com
Of the dlls? From the same build?

Bohdan Szymanik

unread,
Apr 17, 2012, 5:46:22 AM4/17/12
to ravendb
I think you're right, there's a dll mismatch. I installed the
Raven.Client via nuget to a solution but the test code was running as
an fsx script so this is the bit with references and you see it's
supposed to be referencing 1.0.888:

#I @"..\packages\Newtonsoft.Json.4.0.8\lib\net40"
#r "Newtonsoft.Json.dll"

#I @"..\packages\NLog.2.0.0.2000\lib\net40"
#r "NLog"

#I @"..\packages\RavenDB.Client.1.0.888\lib\net40"
#r "Raven.Client.Lightweight.dll"
#r "Raven.Abstractions.dll" // It seems I need to have this here when
running under vs11 but under vs2010 I don't need it?????

#I @"..\packages\RavenDB.Client.FSharp.1.0.888\lib\net40"
#r "Raven.Client.Lightweight.FSharp.dll" // do I need this if I'm
using f# 3????

Error on calling the query { ... } =
System.IO.FileNotFoundException: Could not load file or assembly
'Raven.Client.Lightweight, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=37f41c7f99471593' or one of its dependencies. The
system cannot find the file specified.
File name: 'Raven.Client.Lightweight, Version=1.0.0.0 ...

But I get a sensible response if I just execute:
session.Query<Movie>();;

val it : Raven.Client.Linq.IRavenQueryable<Movie> =
seq
[{Id = null;
Title = "Terminator 2";
Summary = "It was the end of the world";};
{Id = null; ...

I'll try this on a different machine and see how it comes out.

On Apr 17, 7:14 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>

Bohdan Szymanik

unread,
Apr 17, 2012, 5:21:18 PM4/17/12
to ravendb
Hmmm - my error this still doesn't make sense because of course it is
the correct 1.0.0.0 version of Raven.Client.Lightweight that's in the
1.0.888 release.

I then tried to run the script straight out of the Raven client
directory on the downloaded binary distribution - so all required dlls
are in the directory from which the script runs, and still I get an
error to say it can't find the raven.client.lightweight.dll.

So I then tried an experiment and copied the
Raven.Client.Lightweight.dll into the core F# v4.0 framework
directory: C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0
and this time the error changed to this:

System.ArgumentException: Incorrect instance type
Parameter name: obj
at Microsoft.FSharp.Quotations.PatternsModule.checkObj(MemberInfo
membInfo, FSharpExpr obj)
at
Microsoft.FSharp.Quotations.PatternsModule.mkInstanceMethodCall(FSharpExpr
obj, MethodInfo minfo, FSharpList`1 args)
at
Microsoft.FSharp.Quotations.ExprShapeModule.RebuildShapeCombination(Object
shape, FSharpList`1 arguments)
at Microsoft.FSharp.Linq.QueryModule.walk@861-1[a](FSharpFunc`2 f,
FSharpExpr p)
at Microsoft.FSharp.Li...@861-2.Invoke(FSharpExpr
p)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult]
(FSharpFunc`2 mapping, FSharpList`1 x)
at Microsoft.FSharp.Linq.QueryModule.walk@861-1[a](FSharpFunc`2 f,
FSharpExpr p)
at Microsoft.FSharp.Li...@861-2.Invoke(FSharpExpr
p)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult]
(FSharpFunc`2 mapping, FSharpList`1 x)
at Microsoft.FSharp.Linq.QueryModule.walk@861-1[a](FSharpFunc`2 f,
FSharpExpr p)
at Microsoft.FSharp.Li...@861-2.Invoke(FSharpExpr
p)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult]
(FSharpFunc`2 mapping, FSharpList`1 x)
at Microsoft.FSharp.Linq.QueryModule.walk@861-1[a](FSharpFunc`2 f,
FSharpExpr p)
at Microsoft.FSharp.Linq.QueryModule.EvalNonNestedInner(FSharpExpr
queryProducingSequence)
at Microsoft.FSharp.Linq.QueryModule.EvalNonNestedOuter(FSharpExpr
tm)
at <StartupCode$FSI_0004>.$FSI_0004.main@()

The test code (I'm running this straight out of the RavenDB client
directory, hence the comment mark on the include) is:

//#I @"C:\Extras\RavenDB-Build-888\Client"
#r "Newtonsoft.Json.dll"
#r "NLog"
#r "Raven.Client.Lightweight.dll"
//#r "Raven.Abstractions.dll" // do I need this?
#r "Raven.Client.Lightweight.FSharp.dll"

type Movie =
{
Id:string
Title:string
Summary:string
}

// let's try the new F# 3 linq syntax...
let store = new Raven.Client.Document.DocumentStore()
store.Url <- "http://localhost:8080/"
store.Initialize() |> ignore

let session = store.OpenSession()

open System.Linq
open Microsoft.FSharp.Linq

// try something with our movies collection
query { for item in session.Query<Movie>() do
select item
}

Colin

unread,
Apr 18, 2012, 4:18:49 AM4/18/12
to rav...@googlegroups.com
 I'm just looking at this now, too see what it would take to add support for F# query expressions. 

Just to note, you can do something like this

let getMovies : seq<Movie> = 
    use session = docStore.OpenSession()
    raven { 
        return! (query id)
    } |> run session


Cheers Colin

Colin

unread,
Apr 18, 2012, 5:29:37 AM4/18/12
to rav...@googlegroups.com
Update:

 It would seem that if you run the same code from a console app, it can indeed resolve, the Raven.Client.Lightweight library so it would seem to be
a problem with resolving assemblies within FSI. 

Here is the code I have for a simple console app.

open Microsoft.FSharp.Linq
open Raven.Client.Document
open Raven.Client
open Raven.Client.Linq
open System.Linq
open System

let docStore = (new DocumentStore(Url = "http://localhost:8080")).Initialize()

type Movie = {
    mutable Id : string
    Title : string
}

let movies = [
    { Id = null; Title = "Terminator 2" }
    { Id = null; Title = "Terminator 3" }
    { Id = null; Title = "Drive" }
]

let storeMany (data : seq<'a>) =
    raven {
        let results = ref []
        for d in data do
            let! a = store d 
            results :=  a :: !results
        return (!results |> List.rev)
    }  

let setup() =
    use session = docStore.OpenSession()
    raven { 
        return! storeMany movies
    } |> run session

let linqQuery = Linq.QueryBuilder()

let queryExpressionSupport = 
    use session = docStore.OpenSession()
    linqQuery {
         for movie in session.Query<Movie>() do
         where (movie.Title = "Drive")
         select movie.Title  
    }

[<EntryPoint>]
let main(args) =
    printfn "%A" queryExpressionSupport
    Console.ReadLine() |> ignore
    0


On Tuesday, April 17, 2012 1:41:53 AM UTC+1, Bohdan Szymanik wrote:

Bohdan Szymanik

unread,
Apr 18, 2012, 6:10:00 PM4/18/12
to ravendb
Hmm - it's taking me awhile to learn the references I need but I'm
pretty sure I've still got a problem loading them even from a compiled
exe eg:

Unhandled Exception: System.MissingMethodException: Method not found:
'Microsoft
.FSharp.Core.FSharpFunc`2<Raven.Client.IDocumentSession,!!0>
RavenBuilder.Delay(
Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.C
ore.FSharpFunc`2<Raven.Client.IDocumentSession,!!0>>)'.
at Program.setup()
at Program.main(String[] args) in C:\Users\bohdan\documents\visual
studio 11\
Projects\ConsoleApplication1\ConsoleApplication1\Program.fs:line 49

This is while attempting to execute
setup() |> ignore
I'm guessing the ravenbuilder is in
Raven.Client.Lightweight.FSharp.dll? I have this referenced in vs11 on
the project along with Raven.Client.Lightweight and Raven.Abstractions
- this is the same behaviour for me against build 888 and 912 - I can
see you're working on an fsharp sample:)

Colin

unread,
Apr 19, 2012, 10:06:24 AM4/19/12
to rav...@googlegroups.com
Could you send me the example solution, so I can have a look?

Nicolas Spontz

unread,
Apr 30, 2012, 5:36:06 AM4/30/12
to rav...@googlegroups.com
Hi folks,

One thing that might help :  In order to synchronize dependencies in fs files and in fsx environment, I suggest you use the script mentionned here 

It generates a __myproject.fsx which contains all the dependencies of your project, even if it cross-reference another project.
That means the only authoritative source of dependency is your project, and not some gardened text file somewhere.

This might help spot down / limit noise and errors.



PS  : on a totally general ground, I can't believe the dependency pb in CS is still here after sooooo many years.  thought it would be solved by now. i really just cant believe no standard industry wide solution arose in all those years. while it causes so many freaking trouble. 

Bohdan Szymanik

unread,
Apr 30, 2012, 6:28:37 PM4/30/12
to rav...@googlegroups.com
Thanks Nicolas, Colin confirmed i had a problem with my references - when i just used nuget on the ravendb client and fsharp client then the project built and worked. I'll try that script when i get back to my desk - i prefer using the fsx scripts.

Nicolas Spontz

unread,
May 18, 2012, 6:21:49 AM5/18/12
to rav...@googlegroups.com
HI, just hit this problem as well. do you remember what it was ?
Reply all
Reply to author
Forward
0 new messages