c# - Select Contains With CSV But Keep Sort Order -
i have scenario have ilist<guid>
in variable called csv in specific order need keep. doing select contains can topics based in list of guids have.
the guids lucene search ordered original score each luceneresult. why need keep them in order.
var results = _context.topic .where(x => csv.contains(x.id));
however. lose order guids came in this. idea how can keep same order hand list of guids context , topics in same order based on topid.id?
i have tried following mentioned below, doing join still come out in same order? please note paging these results too.
var results = _context.topic .join(csv, topic => topic.id, guidfromcsv => guidfromcsv, (topic, guidfromcsv) => new { topic, guidfromcsv } ) .where(x => x.guidfromcsv == x.topic.id) .skip((pageindex - 1)*pagesize) .take(pagesize) .select(x=> x.topic);
** update **
so have moved away using , guid , attempting pass in lucene model has score property want order by. here have
public pagedlist<topic> gettopicsbyluceneresult(int pageindex, int pagesize, int amounttotake, list<lucenesearchmodel> luceneresults) { var results = _context.topic .join(luceneresults, topic => topic.id, luceneresult => luceneresult.id, (topic, luceneresult) => new { topic, luceneresult } ) .where(x => x.luceneresult.id == x.topic.id) .orderbydescending(x => x.luceneresult.score) .skip((pageindex - 1) * pagesize) .take(pagesize) .select(x => x.topic); var topicresults = results.tolist(); // return paged list return new pagedlist<topic>(topicresults, pageindex, pagesize, topicresults.count); }
however getting following error? doing possible?
unable create constant value of type 'lucenesearchmodel'. primitive types or enumeration types supported in context.
if understand question correctly, want filter topics based on csv , want results in same order csv. if so:
var results = csv .groupjoin(_context.topic, guid => guid, topic => topic.id, (guid, topics) => topics) .selectmany(topics => topics);
it important note treats _context.topic
ienumerable<t>
; therefore, fetch topics database , perform groupjoin on client side, not on database.
edit: based on comment below, answer not want. i'll leave answer here documentation.
Comments
Post a Comment