Finding a customer's gender I have been playing with Async/parallel execution in entity framework for while. I'm not sure if I'm doing it right.

I have two entity contexts: one for reading and one for writing. The reading context has more than 200000 rows in table Customer. It took 9 minutes on my PC (i7+8GB).

let FindGender(skip : int, take : int) : Async&lt;unit&gt; = 
            async { 
                try 
                    use readContext = new ReadContext()
                    use context = new WriteContext()
                    let! customers = Async.AwaitTask 
                                     &lt;| readContext.Customers.OrderBy(fun c -&gt; c.CustomerId).Skip(skip).Take(take)
                                              .ToListAsync()
                    let findGender (c : NA.Data.Entities.Customer) : unit = 
                        let name = context.Names.FirstOrDefault(fun i -&gt; i.Name.ToLower() = c.FirstName.ToLower())
                        match name = Unchecked.defaultof&lt;NameTable&gt; with
                        | false -&gt; 
                            Console.WriteLine(String.Format("{0}", name.Name))
                            // create customer
                            let customer = new Customer()
                            customer.ExternalCustomerId &lt;- c.CustomerId
                            customer.ExternalCustomerName &lt;- c.FirstName
                            customer.GenderId &lt;- name.Gender
                            customer.GenderName &lt;- name.GenderType.ToString()
                            customer.NameListId &lt;- name.NameId
                            context.Customers.Add(customer) |&gt; ignore
                        | _ -&gt; 0 |&gt; ignore

                    customers |&gt; Seq.iter findGender

                    let! _ = Async.AwaitTask &lt;| context.SaveChangesAsync()
                    return()
                with ex -&gt; printfn "Exception handled. %A" ex
            }
        let sw = new Stopwatch()
        sw.Start()
        let customerCount = 218114
        let step = 1000
        [ 0..step..customerCount ]
        |&gt; Seq.map (fun i -&gt; 
               if i + step &lt; customerCount then (i, step)
               else (i, customerCount - i))
        |&gt; Seq.map (fun (step, take) -&gt; FindGender(step, take))
        |&gt; Async.Parallel
        |&gt; Async.RunSynchronously
        |&gt; ignore
        sw.Stop()
        printfn "%A" sw.Elapsed
match name = Unchecked.defaultof&lt;NameTable&gt; with
| false -&gt; …
| _ -&gt; …


If you're checking whether a condition is true, you should use if, not pattern matching. It's simpler and clearer.



0 |&gt; ignore


Instead of this, you can write the unit value: ().