entity framework - LinQ: How to Write single Query to retrieve records while passing List/string collection in efficient way? -


i have written linq query retrieve records more quick way. take more time retrieve while passing local collection values linq query:

here working linq query entity framework. need forumthread based on platformid passed string collection here

goal: how can retrieve records matched id's collection in single linq query more efficient way? ex: slow execution query:

public void getthreadcollection(string[] platformid) {     using (supportentity support=new supportentity())     {         var threadcollection = (from platid in platformid                                 thread in support.forumthread                                 platform in support.platforms                                 platid == thread.platformid &&                                       platform.platformid==platid                                 select new                                 {                                     threadid = thread.threadid,                                     title = thread.title,                                     description = thread.desc,                                     platformname = platform.platformname                                 }).tolist();                             } } 

ex: rewritten code avoid slow execution time sending individual platform id retrieve records using iteration : each: take more less time previous one. not efficient.

ex:

public function(string[] platformid) {     foreach(platid in platformid)     {         using (supportentity support = new supportentity())         {                 var threads = (from thread in support.forumthread                            platform in support.platforms                            platid == thread.platformid &&                                  platform.platformid == platid                            select new                            {                                threadid = thread.threadid,                                title = thread.title,                                description = thread.desc,                                platformname = platform.platformname                            }).tolist();              threadcollection.addrange(threads);                              }     }       } 

can please suggest , how write single query retrieve records more efficient in single query?

to pass in bunch of id's query compare id's in database, typically use contains call instead of looping through (which cause query each iteration of loop, , quite slow). can't quite gather how fit entities since i'm not sure how using (supportentity support = new supportentity()) portion work, here's simple example:

public ienumerable<car> getcarsmatchingids(ienumerable<int> carids) {     using(var dealershipcontext = new dealershipcontext())     {         return dealershipcontext.cars.where(c => carids.contains(c.id));     } } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -