c# - Regarding LINQ Usage in Large Loops -


i wondering recommended in following scenario:

i have large loop traverse id store in database so:

foreach (var rate in rates) {     // id rate name     guid id = dbcontext.differententity         .where(x => x.name == rate.name).firstordefault();      // create new object newly discovered      // id insert database     dbcontext.yetanotherentity.add(new yetanotherentity     {         id = guid.newguid(),         diffid = id,     } } 

would better/ faster instead (first differententity ids, rather querying them separately)?

list<differententity> differententities = dbcontext.differententity;  foreach (var rate in rates) {     // id rate name     guid id = differententities         .where(x => x.name == rate.name).firstordefault();      // create new object newly discovered      // id insert database     dbcontext.yetanotherentity.add(new yetanotherentity     {         id = guid.newguid(),         diffid = id,     } } 

is difference negligible or should consider? advice.

store rate names in sorted string array (string[]) instead of list or collection. use array.binarysearch() make search faster. rest of going write has been written @felipe above.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -