tags:

views:

58

answers:

4

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
}
+1  A: 

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?

Brian Driscoll
Probably. @Soo can test that, anything on LinqResult will fail.
Henk Holterman
A: 

Most likely either Db or Db.Table are null.

LukeH
A: 

It is probably that Db is null. The exception happens when you do the .Any(), but this is because of defered execution.

Phillip Ngan
If Db was `null` then it would throw the exception on the query line.
JaredPar
A: 

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.

JaredPar