I'm using Microsoft's SqlDataConnection type provider. However, the only way I've seen to update a row in the database is to use something similar to this where it updates mutable values:

let updateProduct product = 
  let currentProduct = query {
    for c in context.Product do
    where (c.Product_id = product.ProductId)
    select c } 

let record = currentProduct |> Seq.head

record.Product_name <- product.ProductName
record.Product_count <- Nullable<int>(product.ProductCount)
record.Product_price <- product.ProductPrice

    | ex -> printfn "Error when inserting - %s" ex.Message

In case it's needed, I'm using this Product type:

type Product = {
  ProductId: int
  ProductName: string
  ProductCount: int
  ProductPrice: string

Is there a "more F# way" to handle the update instead of updating the record I find from the database?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.