public Policy[] FindPolicies(FindPolicyRequest req) { Console.WriteLine("Request Receieved"); using (var db = new InsuranceDBContext()) { var policies = db.InsurancePolicies.AsQueryable(); if (req.PolicyType == "Single" || req.PolicyType == "Married" || req.PolicyType == "Family") { policies = policies.Where(x => x.PolicyType == req.PolicyType); } List <Policy> returnList = new List <Policy>(); foreach (var p in policies) { var policy = new Policy() { PolicyName = p.PolicyName, ID = p.ID }; policy.BasePrice = CalculateBasePrice(p, req); returnList.Add(policy); } return(returnList.ToArray()); } }
public void InsertRows() { List <Task> tt = new List <Task>(); for (int i = 1; i <= 1000; i++) { using (var db = new InsuranceDBContext()) { for (int j = 1; j <= 1000; j++) { var ip = new InsurancePolicy() { PolicyName = "No Age Policy X1 " + i * j, BasePrice = 10M + Convert.ToDecimal((i * j) / 100), }; db.InsurancePolicies.Add(ip); } Console.WriteLine("saving group " + i); db.SaveChanges(); Console.WriteLine("saved group " + i); } } //Console.WriteLine("All groups done"); //Parallel.For(0, 1000, (i, si) => //{ // using (var db = new InsuranceDBContext()) // { // Parallel.For(0, 1000, (j, sj) => // { // var ip = new InsurancePolicy() // { // PolicyName = "No Age Policy " + i*j, // BasePrice = 10M + Convert.ToDecimal((i*j)/100), // }; // db.InsurancePolicies.Add(ip); // }); // Console.WriteLine("Saving group " + i); // db.SaveChanges(); // Console.WriteLine("Saved group " + i); // //var finished = // // db.SaveChangesAsync() // // .ContinueWith(t => Console.WriteLine("Inserted " + t.Result + " rows in group " + i)); // //tt.Add(finished); // } //}); //Task.WaitAll(tt.ToArray()); }