Incorrect results when looping over recordset using Webmatrix/Mono/MySQL
I have a test ASP.NET MVC 3 web site running on Mono v2.10.2 on Ubuntu v10.04. I am using MySQL Connector/NET as the database provider.
The test page is doing a simple select query to a MySQL server using the WebMatrix.Data class. When I execute the code, I get the right number of rows returned, but it repeats the same data from one of the rows, rather than showing the correct distinct data for each row.
I am getting this:
username5
username5
usernam开发者_JAVA百科e5
username5
username5
But I should be getting this:
username1
username2
username3
username4
username5
Incidentally, when I run this web site on Windows (easy to do since it is using Mono), I get the correct results for each of the rows. When I execute the query directly against the MySQL server on Ubuntu, I also get the correct result.
The controller looks like this:
var db = Database.OpenConnectionString("server=localhost;database=MyDb;Uid=xxx;Pwd=xxx", "MySql.Data.MySqlClient");
ViewBag.Pools = db.Query("select * from MyTable");
The view looks like this:
@foreach(var p in ViewBag.Pools)
{
<div>@p.username</div>
}
Am I doing something fundamentally wrong here with the way I am using WebMatrix.Data?
精彩评论