fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
572 stars 146 forks source link

No mapping exists for Guid option #578

Open joelvandiver opened 5 years ago

joelvandiver commented 5 years ago

Description

A Guid option is throwing an exception with a query.

Repro steps

  1. Table Definition:

    CREATE TABLE MySchema.MyTable (
      Id               uniqueidentifier NOT NULL
    , ObjectId         uniqueidentifier NULL
    , CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (Id ASC)
    );
  2. Example Script

    
    type DBSchema =
    SqlDataProvider<
            ConnectionStringName = "MyDB",
            DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER,
            UseOptionTypes = true>

let getDB() = DBSchema.GetDataContext(connectionString)

let db = getDB()

let objectId : Guid option = Guid.NewGuid() |> Some

query { for a in db.MySchema.MyTable do where (a.ObjectId = objectId) select a } |> List.ofSeq



### Expected behavior

Guid options to be treated as NULL when querying against the db when using 'UseOptionTypes'.

### Actual behavior

**Exception raised:**
`No mapping exists from object type Microsoft.FSharp.Core.FSharpOption`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.`
Thorium commented 5 years ago

I thought this would have been already working. As a workaround you can use:

query {
    for a in db.MySchema.MyTable do
    where (a.ObjectId.IsSome && a.ObjectId.Value = myGuid)
    select a
} |> List.ofSeq
joelvandiver commented 5 years ago

Thanks for the workaround!

I'm not sure why this isn't working either. I've had this Guid option for several months now and haven't run into until recently.

Thorium commented 3 years ago

I guess it was some change in SQL server driver. This should be also now fixed in version 1.1.94 by fe60096c1700ca78f7e8ba5948eda9f7be2ea35c