c# - How to speed up a linq statement that checks two lists for missing records -
what trying achieve.
i working on reconcile process , need ensure database table has correct entries. need find records in table not in master list. when have found these entries need group them , find recent in each group. if operation fields of recent entries defined “added”, need add additional records operation fields marked “deleted”, not defined in master list.
the code have written selects records in database not in master list. groups these , orders them , select first item in each group newest in each group. return items have operation defined “added”. have run code against unit tests , “real” data. although works, slow taking maybe forty seconds when run against database of 16 thousand records (when run within visual studio). can advise on if possible modify code improve speed?
shown below code finds mismatched records
var linksindb = _ctx.linkrecords.tolist(); return (from dbl in linksindb select dbl) .except( dbl in linksindb l in links dbl.ep1id == l.endpoints[0].entitykey.entityid && dbl.ep2id == l.endpoints[1].entitykey.entityid select dbl) .groupby(x => new {x.ep1id, x.ep2id}, (key, g) => g.orderbydescending(x => x.lastmodifieddate_utc).first()) .where(x => x.operation == "added") .tolist();
nb. master list called "links" generic list of type link same type returned _ctx.linkrecords.tolist();
Comments
Post a Comment