Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

try
    context.DataContext.SubmitChanges()
with
    | ex -> printfn "Error when inserting - %s" ex.Message

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

[<CLIMutable>]
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?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.