private void SavaJobsToDatabase(List <Job> jobs) { db.jobTable.DeleteAllOnSubmit(db.jobTable.ToList <JobTable>()); foreach (Job job in jobs) { if (db.jobTable.Any(c => c.Job_ID.Equals(job.Id))) { continue; } JobTable jobItem = new JobTable() { Job_ID = job.Id, Job_AddressCity = job.Address.City, Job_AddressDetail = job.Address.Detail, // Job_AddressLatitude=job.Address.Accurate.Latitude, // Job_AddressLongitude=job.Address.Accurate.Longitude, Job_CompanyId = job.Company.Id, Job_CompanyName = job.Company.Name, Job_Url = job.Url, Job_StartTime = job.StartTime, // Job_EndTime=job.EndTime+"", Job_IsCollection = false, Job_IsRemind = false, Job_University = job.Address.University, }; if (job.Address.Accurate != null) { jobItem.Job_AddressLatitude = job.Address.Accurate.Latitude; jobItem.Job_AddressLongitude = job.Address.Accurate.Longitude; } try { //wait for my turn OperationOnDatabase.WaitOne(); //interact with the database //use 'ToArray' to make sure we are indeed done //with our DataContext before we continue db.jobTable.InsertOnSubmit(jobItem); } finally { //always give my turn away when done. OperationOnDatabase.Set(); } // if(!db.jobTable.Contains<JobTable>(jobItem,new JobEqualityComparer())) } // int count = db.jobTable.Count(); db.SubmitChanges(); // count = db.jobTable.Count(); }
public JobTable GetJobById(string jobId) { try { //wait for my turn OperationOnDatabase.WaitOne(); //interact with the database //use 'ToArray' to make sure we are indeed done //with our DataContext before we continue return(db.jobTable.FirstOrDefault(c => c.Job_ID.Equals(jobId))); } finally { //always give my turn away when done. OperationOnDatabase.Set(); } }