What could be causing this error:
NullReferenceException was unhanded, Object reference not set to an instance of an object.
var LinqResult =
from a in Db.Table
select new {Table = a};
if(LinqResult.Any())
{
//Blah blah blah
}
What could be causing this error:
NullReferenceException was unhanded, Object reference not set to an instance of an object.
var LinqResult =
from a in Db.Table
select new {Table = a};
if(LinqResult.Any())
{
//Blah blah blah
}
My guess is that either Db or Db.Table has not yet been instantiated at the point of execution of that query. Can you post any additional code for context?
It is probably that Db is null. The exception happens when you do the .Any(), but this is because of defered execution.
The Db.Table
value is null
.
It is not Db
being null
as other people have suggested. Else the exception would have occured on the actual query.