I'm using ASP.NET MVC with C# with Entity Framework 6. I have the following 3 lines of code. x
is true.
var x = new List<string>(){"FOO", "BAR"}.Contains("FOO");
var foo = db.TableName.Where(n => new List<string>() { "FOO", "BAR" }.Contains("FOO"));
var bar = foo.ToList();
On the third line an error is thrown: Object reference not set to an instance of an object.
For full clarity, the following lines do not throw any error:
var x = false;
var foo = db.TableName.Where(n => false);
var bar = foo.ToList();
All of the answers I've looked at say that I should check to make sure the list isn't null. I tried that to no avail, then tried defining the list in the LINQ Where call to try to localize the problem. Neither worked.
Why is this throwing an error? What can I do to fix it?