Querying the entity framework (4.1) DbContext does not return any results
Using Entity Framework 4.1 with SQL Server 2008 R2 Express.
I have a strongly typed DbContext (ctx in code) with IDbSet<Users> property which represents a table [Users] in the database. When I execute:
var result = ctx.Users.ToList();
The result.Count is 0 as if there is nothing in the database although there are records in that table. I've checked the ctx.Database.Con开发者_JAVA技巧nection and it does have the right connection string.
I executed
ctx.Users.ToString()
to get the SQL that will be executed and when I execute the given statement in the SQL management studio I do get the list of users.
It seems as if the query is never executed and I am unable to detemine what could be the problem.
Everything is fine. It did not read the correct connection string and it created an empty database instead :). Thx everybody for the effort
Do any other tables work ? That will prove the connection string.
When you test in management studio make sure you are connecting as the same user as your connection string.
If both those tests pass it may be an issue with the name 'Users'? (Users was OK as a name in 4.0 but I've not tried it in 4.1 so its a potential area to look at)
精彩评论