Reputation: 23207
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
}
Upvotes: 1
Views: 318
Reputation: 755587
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.
Upvotes: 0
Reputation: 16126
It is probably that Db is null. The exception happens when you do the .Any(), but this is because of defered execution.
Upvotes: 0
Reputation: 19635
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?
Upvotes: 1