How can I test a LINQ Query such as the following:
var vUser = (from u in this.dbName.aspnet_Users
where u.UserName.Equals(this.wCreateUser.UserName)
select u).Single();
I keep getting a null exception for vUser, however I am positive such a user exists.
The record would have to exist or the exception would have to be thrown during evaluation of the lambda, otherwise the exception thrown would be to the effect of
Are you accessing any properties on the
vUserobject after the query or is thethis.wCreateUserobject possibly null?Edit: for comments..
If the exception is that the sequence contains no elements, the query being generated is not returning a result. I would recommend you examine the query being generated and test it directly against the SQL Server..
You can do this a few ways.
query being executed.
output of the query (example
below)..
.