0 people like it.

What is wrong with the use of join here?

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
// Trying to make an SQLite version of 
// https://github.com/theimowski/SuaveMusicStore/blob/master/Db.fs


module SreyasMusicStore.Db

open FSharp.Data.Sql


// create a type alias with the connection string and database vendor settings
type mSql = SqlDataProvider< 
              ConnectionString = @"Data Source=C:\Users\labuser\Documents\Projects\SreyasMusicStore\MySMS.db ;Version=3",
              DatabaseVendor = Common.DatabaseProviderTypes.SQLITE,
              ResolutionPath = @"C:\Users\labuser\Documents\Projects\SreyasMusicStore\packages\SQLProvider.0.0.9-alpha\docs\sqlite",  // @"F:\sqlite\3",
              IndividualsAmount = 1000,
              UseOptionTypes = true 
            >

type DbContext = mSql.dataContext
type Album = DbContext.``[main].[Albums]Entity`` // .``[dbo].[Albums]Entity``
type Genre = DbContext.``[main].[Genres]Entity``
//type AlbumDetails = DbContext.``[main]. // [AlbumDetails]Entity``

let getContext() = mSql.GetDataContext()

let firstOrNone s = s |> Seq.tryFind (fun _ -> true)

let getAlbums (ctx : DbContext) : Album list =
    ctx.``[main].[Albums]`` |> Seq.toList


let getGenres (ctx : DbContext) : Genre list =
    ctx.``[main].[Genres]`` |> Seq.toList

let getAlbumsForGenre genreName (ctx : DbContext) : Album list =
    query {
        for album in ctx.``[main].[Albums]`` do
            join genre in ctx.``[main].[Genres]``  on ( album.GenreId = genre.GenreId )
                where ( genre.Name = genreName )
                select album
    }
    |> Seq.toList


// C:\Users\labuser\Documents\Projects\SreyasMusicStore\Db.fs(13,13): Error FS3097: Incorrect syntax for 'join'. Usage: join var in collection on (outerKey = innerKey). Note that parentheses are required after 'on'. (FS3097) (SreyasMusicStore)

// C:\Users\labuser\Documents\Projects\SreyasMusicStore\Db.fs(13,13): Error FS3098: 'join' must come after a 'for' selection clause and be followed by the rest of the query. Syntax: ... join var in collection on (outerKey = innerKey). Note that parentheses are required after 'on' ... (FS3098) (SreyasMusicStore)
namespace SreyasMusicStore
module Db

from SreyasMusicStore
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Data
type mSql = obj

Full name: SreyasMusicStore.Db.mSql
type DbContext = obj

Full name: SreyasMusicStore.Db.DbContext
type Album = obj

Full name: SreyasMusicStore.Db.Album
type Genre = obj

Full name: SreyasMusicStore.Db.Genre
val getContext : unit -> 'a

Full name: SreyasMusicStore.Db.getContext
val firstOrNone : s:seq<'a> -> 'a option

Full name: SreyasMusicStore.Db.firstOrNone
val s : seq<'a>
module Seq

from Microsoft.FSharp.Collections
val tryFind : predicate:('T -> bool) -> source:seq<'T> -> 'T option

Full name: Microsoft.FSharp.Collections.Seq.tryFind
val getAlbums : ctx:DbContext -> Album list

Full name: SreyasMusicStore.Db.getAlbums
val ctx : DbContext
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
val getGenres : ctx:DbContext -> Genre list

Full name: SreyasMusicStore.Db.getGenres
val getAlbumsForGenre : genreName:'a -> ctx:DbContext -> Album list

Full name: SreyasMusicStore.Db.getAlbumsForGenre
val genreName : 'a
val query : Linq.QueryBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.query
val album : obj
custom operation: join var in collection on (outerKey = innerKey). Note that parentheses are required after 'on'

Calls Linq.QueryBuilder.Join
val genre : obj
custom operation: where (bool)

Calls Linq.QueryBuilder.Where
custom operation: select ('Result)

Calls Linq.QueryBuilder.Select
Raw view Test code New version

More information

Link:http://fssnip.net/rr
Posted:8 years ago
Author:
Tags: