static private TagCombinationDetail createTcdtDataToInsert(long id, long tcId, String tagName, long tagCount, double percent) { TagCombinationDetail tagCombinationDetail = new TagCombinationDetail(); tagCombinationDetail.Id = id; tagCombinationDetail.TcId = tcId; tagCombinationDetail.TagKey = tagName; tagCombinationDetail.Count = tagCount; tagCombinationDetail.Percent = percent; return(tagCombinationDetail); }
static public void checkDbRawQuery() { cleanDatabase(); String tag_counts = ""; long TC_ID = 1; long TCD_ID = 1; List <Country> countries = getAllCountriesFromDB(); foreach (Country country in countries) { Console.WriteLine("COUNTRY : " + country.Name); List <TagsKeyValue> tagsList = getAllTagsFromDB(); Console.WriteLine("Length of tags " + tagsList.Count); foreach (TagsKeyValue tag in tagsList) { String tag_key = tag.Key; String tag_value = tag.Value; Console.WriteLine("Key : " + tag_key + " and Value: " + tag_value); long tagTotalCount = getTagCount(country.Db, tag_key, tag_value); if (tagTotalCount == -1) { Console.WriteLine("ERROR. ABORT"); //Break, there is something wrong. } tag_counts = tagTotalCount.ToString(); List <TagAggregation> listOfTags = getAllTagsRespectively(country.Db, tag_key, tag_value, tag_counts); Console.WriteLine("List Size " + listOfTags.Count); Double average = getAverageNumberOfTags(country.Db, tag_key, tag_value); List <String> topNtags = new List <string>(); int temp = 0; foreach (TagAggregation tagAggregation in listOfTags) { topNtags.Add(tagAggregation.tag); } TagCombination tagCombination = createTctDataToInsert(TC_ID, tag.Id, country.Id, tagTotalCount, average, topNtags.ToArray()); insertTagCombinationData(tagCombination); foreach (TagAggregation tags in listOfTags) { TagCombinationDetail tagCombinationDetail = createTcdtDataToInsert(TCD_ID, TC_ID, tags.tag, tags.count, Math.Round(tags.percent, 2)); insertTagCombinationDetailData(tagCombinationDetail); TCD_ID++; } TC_ID++; } } }
static private void insertTagCombinationDetailData(TagCombinationDetail tagCombinationDetail) { using (tag_qualityContext db = new tag_qualityContext()) { db.Set <TagCombinationDetail>().Add(tagCombinationDetail); try { int records = db.SaveChanges(); //Console.WriteLine("Saved {0} Tag Combination Detials to DB", records); } catch (DbUpdateException e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.WriteLine(e.InnerException); } } }