I have a huge list of strings and I want to compare a database table's records with it. What is the best solution?
You can suppose specified table's name is ATable
and its structure is like:
public class ATable
{
[Key]
public long Id{get;set;}
[Key]
public long Name{get;set;}
}
I wrote the following code
using(var context = new MyDbContext())
{
context.Log = (log) => {Console.WriteLine(log)};
var result = context.ATables.Where(item => hugeList.Contains(item.Name)).ToList();
}
I checked generated logs and I saw that above code translated to SQL IN(...)
statement and because of hugeness of list application crash.
I'm sure there is a good way to solve this problem, then you professionals can show me right one.
Thanks