partial void Deletecat_count(cat_count instance);
partial void Insertcat_count(cat_count instance);
partial void Updatecat_count(cat_count instance);
//get categories from item table //count number of occurances for each //insert into table vaules category - category count //return ordered list in decending order public void SetCategoryCount() { DataClasses1DataContext context = new DataClasses1DataContext(); var result = from i in context.tblItems select i.item_category; var d = result.Distinct(); List<string> dlist = d.ToList<string>(); foreach (string s in d) { //update var query= from update in context.cat_counts where update.category_id==s select update; m_log.Add(query.ToString()); var cnt = context.tblItems.Count(p => p.item_category == s); foreach(cat_count up in query) { dlist.Remove(up.category_id); up.category_count = cnt; }//update try { context.SubmitChanges(); m_log.Add(context.Log.ToString()); } catch (Exception e) { string er = e.Message; } } foreach (string s in dlist) { var cnt = context.tblItems.Count(p => p.item_category == s); cat_count catcnt = new cat_count(); catcnt.category_id = s; catcnt.category_count = cnt; try { context.cat_counts.InsertOnSubmit(catcnt); context.SubmitChanges(); m_log.Add(context.Log.ToString()); } catch (Exception e) { string er = e.Message; } } }