I have a LINQ to SQL query that when executed does not return any data. However, when I debug, I can take the generated SQL query, plug in the values for the variables, and run it in SQL Management Studio to get the record I'm expecting. I'm taking the values for the variables while in debug mode as well.
Has anyone experienced something like this before?
As requested, LINQ statement (edited table and column names):
var q1 = from rr in db.ABC
from rd in db.DEF
where rr.a == rd.b
where rr.c == rd.c
where rr.d.Equals(id)
where rr.c.Equals(anotherId)
select new
{
rr.d, rr.x, rr.a,
rr.y, rr.z, rr.v,
rr.e, rd.r
};
var r开发者_开发问答1 = q1.Single();
I'm using very similar queries in other places with success.
Run the SQL Server profile, take the EXACT query it's running (you shouldn't have to "plug in" any values), and run that.
Are you still obtaining results?
Is it plugging in the correct values?
Are you querying a nullable value?
Could you show us the code and generated query?
I would double check the connection string that LINQ to SQL is using. It might just be hitting the wrong database.
Have you run Profiler to make sure the values you think the stament is going to have are actually inthe statment that was sent to the server?
精彩评论