private List<order_detail> GetOrderDetail(int ServiceProviderId) { List<order_detail> ReturnList = new List<order_detail>(); foreach (OrderDetail od in SyncClient.GetOrderDetail(GetFromDate, DateTimeNow, ServiceProviderId)) { order_detail tmp = QueryOrderDetail(od.Id); Boolean NewValue = false; if (tmp == null) { tmp = new order_detail(); NewValue = true; } tmp.address_1 = od.Address1; tmp.address_2 = od.Address2; tmp.city = od.City; tmp.company = od.Company; tmp.country_id = od.CountryId; tmp.createdAt = System.DateTime.Parse(od.CreateDat); tmp.Id = od.Id; tmp.phone_1 = od.Phone1; tmp.phone_2 = od.Phone2; tmp.tax_number = od.Taxnumber; tmp.zip = od.Zip; tmp.first_name = od.Firstname; tmp.last_name = od.Lastname; tmp.order_id = od.OrderId; tmp.zone_id = od.ZoneId; if (NewValue) { dbContext.Set<order_detail>().Add(tmp); } dbContext.SaveChanges(); ReturnList.Add(tmp); } return ReturnList; }