문제

I am trying to build a simple Count function in F# 3.0 with OrmLite which looks like this :

let x = 
    use conn = dbFactory.Open() //IDbConnection
    conn.Count<Area>(fun (x:Area) -> x.parent_id.GetValueOrDefault(0) > 0)

where

type Area() =
    //...
    member val parent_id = Nullable<_>() with get, set

But I get the error :

System.InvalidOperationException: variable 'x' of type 'FSI_0029.Area' referenced from scope '', but it is not defined

The following works :

let x = 
    use conn = dbFactory.Open()
    conn.Count<Area>(fun (x:Area) -> x.id > 0)

So I assume it has to do with the Nullable<_> type.

Has anyone encountered this issue ?

Many thanks in advance,

도움이 되었습니까?

해결책

Typically the functions associated with the member variable needs to be mapped in the Sql builder(for Expressions); for example string's ToUpper() function is mapped internally to sql's UPPER() function. Since the Sql Builder does not know what is GetValueOrDefault (as this function is not mapped to any SQL function) , it is erroring out. I'm not sure what SQL statement can be used for this, if you have a valid case for it, please create a ticket in the Github.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top