public async Task <int> CountWords(filter f) { var q = (from c in this.words_list select c); q = setWordListQueryFilter(f, q); return(await q.CountAsync()); }
public async Task <word_param[]> getPage(filter f, int start, int pageSize) { var q = (from c in this.words_list.AsNoTracking() select c); q = setWordListQueryFilter(f, q); if (f.isInverse) { q = q.OrderBy(c => c.reverse).ThenBy(c => c.field2).Skip(start * pageSize).Take(pageSize); } else { q = q.OrderBy(c => c.digit).ThenBy(c => c.field2).Skip(start * pageSize).Take(pageSize); } //var sql = q.ToSql(); return(await q.ToArrayAsync()); }
public async Task <word_param_base> searchWord(filter f, string word) { string w = f.isInverse == true?sharedTypes.atod(new string(word.Reverse().ToArray()), talpha) : sharedTypes.atod(word, talpha); int start = 0; var q = (from c in this.words_list select c); q = setWordListQueryFilter(f, q); if (f.isInverse) { q = q.OrderBy(c => c.reverse).ThenBy(c => c.field2); start = await(from c in q where w.CompareTo(c.reverse) > 0 select c).CountAsync(); } else { q = q.OrderBy(c => c.digit).ThenBy(c => c.field2); start = await(from c in q where w.CompareTo(c.digit) > 0 select c).CountAsync(); } int pagenumber = start / 100; int count = q.Count(); if (count <= start) { q = q.Skip((start - 1)).Take(1); } else { q = q.Skip(start).Take(1); } word_param wp = await q.FirstOrDefaultAsync(); word_param_base r = null; if (wp != null) { r = (new word_param_base() { CountOfWords = count, wordsPageNumber = pagenumber, accent = wp.accent, digit = wp.digit, field2 = wp.field2, field5 = wp.field5, field6 = wp.field6, field7 = wp.field7, isdel = wp.isdel, isproblem = wp.isproblem, nom_old = wp.nom_old, own = wp.own, part = wp.part, reestr = wp.reestr, reverse = wp.reverse, suppl_accent = wp.suppl_accent, type = wp.type }); } return(r); }
// перетворення рядка в код (якщо не потрібно враховувати \', то askip=true) private IQueryable <word_param> setWordListQueryFilter(filter f, IQueryable <word_param> q) { if ((f.isStrFiltering) && (!string.IsNullOrEmpty(f.str))) { string s = sharedTypes.atod(f.str, talpha); //switch (f.fetchType) //{ // case FetchType.StartsWith: // q = q.Where(c => c.digit.StartsWith(s)); // //q = q.Where(c => c.reestr.Replace("\"","").StartsWith(f.str)); // break; // case FetchType.EndsWith: // q = q.Where(c => c.digit.EndsWith(s)); // //q = q.Where(c => c.reestr.Replace("\"", "").EndsWith(f.str)); // break; // case FetchType.Contains: // q = q.Where(c => c.digit.Contains(s)); // //q = q.Where(c => c.reestr.Replace("\"", "").Contains(f.str)); // break; //} q = q.Where(c => EF.Functions.Like(c.digit, s)); } if (f.ispclass) { q = q.Where(c => c.type == f.pclass); } if (f.ispofs) { if (f.pofs > 70) { q = q.Where(c => c.part == f.pofs); } else { q = q.Where(c => ((c.parts.gr_id == f.pofs) && (c.part < 70))); } } return(q); }