Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 03 23:33
    jkone27 commented #555
  • May 19 12:27
    halcwb edited #732
  • May 19 09:12
    halcwb edited #732
  • May 19 09:12
    halcwb opened #732
  • May 14 11:47
    Volen99 commented #462
  • May 10 07:13
    username1565 commented #286
  • Apr 26 19:52
    gordonfranke commented #719
  • Apr 26 19:50
    gordonfranke commented #719
  • Apr 22 15:02
    bisen2 commented #731
  • Apr 22 08:54
    Thorium commented #731
  • Apr 20 19:11
    bisen2 commented #731
  • Apr 20 18:12
    Thorium commented #731
  • Apr 20 18:10
    Thorium commented #731
  • Apr 20 18:10
    Thorium commented #731
  • Apr 20 17:18
    bisen2 opened #731
  • Apr 14 20:33
    JordanMarr closed #726
  • Apr 14 13:55

    Thorium on master

    Fix for #729 Merge branch '1.1.x' (compare)

  • Apr 14 13:54

    Thorium on 1.1.x

    Fix for #729 (compare)

  • Apr 14 12:53
    torbonde commented #180
  • Apr 14 12:12
    pezipink commented #180
Vincent B.
@evilz
I added the specific version in project but it still not good <PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
Tuomas Hietanen
@Thorium
the Nuget package reference is not enough, dll has to be near in the ResolutionPath
DavidSSL
@DavidSSL
Hey guys, I am on Windows 10 box and I would like to get SQLProvider to work for Postgres. (I was able to get it to work form MSSQL). I followed the instructions here https://github.com/fsprojects/SQLProvider/tree/master/tests/SqlProvider.Core.Tests/Postgres using .net core 3.0.100 but then found dotnet/fsharp#6326. However, I still experience the same problem despite trying the various workarounds suggested.
Are there any up to date instructions on how to get this working?
Tonino Lucca
@tonyx
@DavidSSL the "hack" I found is referencing in the sources a specific version of Npgsql.dll different from the one referenced in the .fsproj. I mean, this is how I do set the resolution path: let [<Literal>] resPath = "/Users/someUser/Projects/orderssystem_core/packages/Npgsql.2.2.1/lib/net45/" , whereas the .fsproj has this reference <PackageReference Include="Npgsql" Version="4.0.7" />. Seems strange but that's it, for now. (see all in this file just in case: https://github.com/tonyx/orderssystem_core/blob/master/Db.fs)
DavidSSL
@DavidSSL
@tonyx . Thanks for your help.
Tonino Lucca
@tonyx
@DavidSSL Did it fix the problem?
DavidSSL
@DavidSSL
@Antonio it didn't work for me. However, I was able to get it working from the following information: https://github.com/fsprojects/SQLProvider/issues/575#issuecomment-506334010
Paul Agron
@nimzi
I'm using NetCore 2.2 on a mac and having difficulty even building with SQLProvider dependencies
Wondering if folks have experience in this area they might share. Does it really work?
Tonino Lucca
@tonyx
@nimzi Is db up and running when editing/compiling?
spingee
@spingee
Hi, is it possible to generate sql without running query/submit?
metatron-the-chronicler
@metatron-the-chronicler
Is it possible to create a generic method that can wrap something like ctx.someEntity |> Seq.toList |> List.map(fun g -> g.MapTo<'a>()) in an Option where 'a is a record?
Tuomas Hietanen
@Thorium
@spingee , yes, for the database context you can do ctx.GetUpdates() and then ctx.ClearUpdates()
...or print the SQL you can subscribe to the event: FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O")
metatron-the-chronicler
@metatron-the-chronicler
Is there a built in way to return IQueryable<T> option from query expressions without materializing the query first?
Shravan
@Sharavanth

Hi

Am new to F# and I cannot get SqlProvider to work with Visual Studio 2017.
Can you please point me to a walkthrough

IsaacR24
@IsaacR24
Hi -- I'm not able to create new rows, only query existing rows
I'm using Azure SQL and Common.DatabaseProviderTypes.MSSQLSERVER
when I call GetDataContext().SubmitUpdates(), it returns unit (no error)
I'm also quite sure that I'm creating a row in the same context
also using the prefered Create method,
1:
let emp = ctx.Main.Employees.Create(FirstName, LastName)("Don", "Syme")
which returns no error
IsaacR24
@IsaacR24
let emp = ctx.Main.Employees.``Create(FirstName, LastName)``("Don", "Syme")
that's what I meant to write re creating a row
Tuomas Hietanen
@Thorium
@IsaacR24 does it do anything if you have FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O") and do SubmitUpdates()?
@metatron-the-chronicler I'm not sure what you mean, but if the question is "can I get SQL out without execution", the answer is no. For almost all other questions the answer is yes.
@Sharavanth what DB? what platform?
Ghost
@ghost~5f1d0ab8d73408ce4fea8ca1
I'm having the same problem as @IsaacR24 - I can query existing rows, but not able to create new rows. I'm running VS 2019 on Windows.
Ghost
@ghost~5f1d0ab8d73408ce4fea8ca1
I'm using SQLProvider 1.1.76
Ghost
@ghost~5f1d0ab8d73408ce4fea8ca1
let [<Literal>] connStr = "Server=(local);Database=DuxCommerce;User Id=DuxAdmin;Password=Password1;"
type DuxCommerce = SqlDataProvider<Common.DatabaseProviderTypes.MSSQLSERVER, 
                                   ConnectionString = connStr, 
                                   UseOptionTypes = true>

let context = DuxCommerce.GetDataContext()

let insertProduct id name price = 
    let product = context.Dbo.Products.Create()
    product.Id <- id
    product.Name <- name
    product.Price <- price
    context.SubmitUpdates

let getProduct (name:string) = 
    query {
        for product in context.Dbo.Products do
        where (product.Name = name)
        select product
    } |> Seq.toList
Ghost
@ghost~5f1d0ab8d73408ce4fea8ca1
It turns out this is a known issue - fsprojects/SQLProvider#645
Cody Johnson
@Shmew
that's odd it works fine for me on 1.1.91 with a local ms sql server in vs 2019
Ghost
@ghost~5f1d0ab8d73408ce4fea8ca1
@Shmew Just curious. Do you use .net core 3.x?
Cody Johnson
@Shmew
yeah 3.1.302
targets netcoreapp3.1
I'll be deploying this app to our development environment today so I guess we'll see if it works with an actual server
Tuomas Hietanen
@Thorium
@ghost~5f1d0ab8d73408ce4fea8ca1 context.SubmitUpdates is a function so you have to call context.SubmitUpdates()
your current code is returning a function that is never called
martyjt
@martyjt
Hi Great project. I'm just wondering the best way to update multiple entities. I basically generated all the typed objects in C# using the entity framework in a separate project using EF - and I am mapping to those objects . when I want to save changes from those objects - how do I do that? Map it back to new SQLProviderobjects and save? Will that update the original entities that way?
Tuomas Hietanen
@Thorium
I have one case where I do even this:
let ``set entity data from elements`` (my:DataContextMy) tablePrefix (entityData:DataContextMy.``dbo.myEntity``) (elements:((string*string)[])) =
    elements
    |> Array.filter(fun (k, v) -> entityData.HasColumn(tablePrefix + k, StringComparison.InvariantCultureIgnoreCase))
    |> Array.distinctBy(fun (k, v) -> k)
    |> Array.iter(fun (k, v) ->
            entityData.SetColumn(tablePrefix + "_" + k,v)
    )
    do! my.SubmitUpdates2()
Tuomas Hietanen
@Thorium
however, the best practice is doing the updates as typed, query what you need, and then just set the columns you want, and do your .SubmitUpdates()
Tuomas Hietanen
@Thorium
Edit, this is other non-best-practice to update only few columns dynamically:
/// Updates myTable field(s) without fetching the whole entity.
/// This is done because the entity that is being updated is un-attached from the database context
/// to avoid transactions expanding over web-service calls.
let ``update some fields to MyTable`` entityId colValues =
    // create transaction, see https://github.com/fsprojects/SQLProvider/issues/238#issuecomment-216226084
    writeWithDbContextAsync <| fun (dbContext:DataContext) ->
        async {
            let newItem = dbContext.MyDataBase.MyTable.Create()
            newItem.Id <- entityId
            colValues |> List.iter(fun (columnName, columnValue) ->
                do newItem.SetColumn<string>(columnName, columnValue)
            )
            newItem._State <- Common.EntityState.Modified (colValues |> List.map fst)
            do! dbContext.SubmitUpdates2()
        }
Kurt Mueller
@kurt-mueller-osumc
I was wondering if anybody had any experience inserting rows into a table with an postgres enum column type? I get the following error:
The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not get columns for `public.table_name`, the type `enum_name` is unknown to Npgsql type mapping
Steve
@hez2010

Hello, I'm trying to use SQLProvider with composite queries on .NET 5, but seems the query p didn't get generated at all:

let minute = 10
let q = 
    query {
        for c in ctx.Public.Plans do
            for d in c.``public.Records by Id`` do
                join f in ctx.Public.Salaries on (d.UserId = f.UserId)
                where (c.Minutes > minute)
                sortBy c.Id
                select (c.Id, c.StartTime, c.EndTime, d.OvertimeMinutes, d.WorkPlanId, d.UserId, d.Note, f.ValidHours)
    }

let p = 
    query {
        for m in q do
            let (_, _, _, _, _, userId, _, validHours) = m
            where (validHours > 3)
            select (userId, validHours)
    } |> Seq.toArray

which generated:

SELECT "arg1"."Id" as "arg1.Id","arg1"."StartTime" as "arg1.StartTime","arg1"."EndTime" as "arg1.EndTime","d"."OvertimeMinutes" as "d.OvertimeMinutes","d"."WorkPlanId" as "d.WorkPlanId","d"."UserId" as "d.UserId","d"."Note" as "d.Note","f"."ValidHours" as "f.ValidHours" FROM "public"."Plans" as "arg1" INNER JOIN  "public"."Records" as "d" on "d"."WorkPlanId" = "arg1"."Id" INNER JOIN  "public"."Salaries" as "f" on "d"."UserId" = "f"."UserId" WHERE (("arg1"."Minutes" > @param1))ORDER BY "arg1"."Id"  -- params @param1 - 10;
Tuomas Hietanen
@Thorium
@hez2010 so the query worked but the later condition was executed in .NET side rather than in SQL
Tuomas Hietanen
@Thorium
btw, anyone wanting to work a lot with this tool (and f#), our company is hiring (mainly near London)... we have a financial platform containing around 10k code lines of small queries, no existing bug list and around 200k users.
Edmund Higham
@ehigham
@kurt-mueller-osumc did you ever make progress with this? Wondering because I have the same issue and am trying to figure out if I can supply my own type mappings