Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="fakeiisexpress.fs" />
Expand Down
41 changes: 31 additions & 10 deletions src/SqlClient.DesignTime/SqlClientExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,40 @@ type internal TypeInfoPerConnectionStringCache() =

let internal sqlDataTypesCache = new TypeInfoPerConnectionStringCache()
let internal findTypeInfoBySqlEngineTypeId (connStr, system_type_id, user_type_id : int option) =
assert (sqlDataTypesCache.ContainsConnectionString connStr)

sqlDataTypesCache.GetTypesForConnectionString connStr
|> Array.filter(fun x ->
let result =
if not (sqlDataTypesCache.ContainsConnectionString connStr) then
failwithf
"Type info cache does not contain an entry for connection string '%s'. \
This may be caused by a cache invalidation race — try reloading the project. \
See https://github.com/fsprojects/FSharp.Data.SqlClient/issues/354"
connStr

let matches =
sqlDataTypesCache.GetTypesForConnectionString connStr
|> Array.filter (fun x ->
x.SqlEngineTypeId = system_type_id &&
(user_type_id.IsSome && x.UserTypeId = user_type_id.Value || user_type_id.IsNone && x.UserTypeId = int system_type_id)
result
)
|> Seq.exactlyOne
(user_type_id.IsSome && x.UserTypeId = user_type_id.Value
|| user_type_id.IsNone && x.UserTypeId = int system_type_id))

match matches with
| [| single |] -> single
| [||] ->
failwithf
"No SQL type found in cache for SqlEngineTypeId=%d, UserTypeId=%A. \
This may be caused by a cache invalidation race — try reloading the project. \
See https://github.com/fsprojects/FSharp.Data.SqlClient/issues/354"
system_type_id user_type_id
| multiple ->
failwithf
"Ambiguous SQL type: %d matches found for SqlEngineTypeId=%d, UserTypeId=%A: %A"
multiple.Length system_type_id user_type_id [| for t in multiple -> t.TypeName |]

let internal findTypeInfoByProviderType(connStr, sqlDbType) =
assert (sqlDataTypesCache.ContainsConnectionString connStr)
if not (sqlDataTypesCache.ContainsConnectionString connStr) then
failwithf
"Type info cache does not contain an entry for connection string '%s'. \
This may be caused by a cache invalidation race — try reloading the project. \
See https://github.com/fsprojects/FSharp.Data.SqlClient/issues/354"
connStr

sqlDataTypesCache.GetTypesForConnectionString connStr |> Array.find (fun x -> x.SqlDbType = sqlDbType)

Expand Down
Loading