Last post Sep 11, 2017 09:28 PM by Lannie
Sep 11, 2017 06:09 AM|doubleagentj|LINK
Using a MySqlConnection instance I want to be able to store the result of a MySqlCommand as a defined C# Class or a List<T>.
For instance I have a data model class User.cs and I want to map the result of the MySqlCommand to an instance of this class.
Something like this:
var sql = @"SELECT * FROM User WHERE UserID = @userId;";
using (var conn = new MySqlConnection(connStr))
User user = new MySqlCommand(sql, conn);
Sep 11, 2017 03:21 PM|PatriceSc|LINK
And you can't use Entity Framework that does this already? Try
https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html (edit: and check
https://msdn.microsoft.com/en-us/library/aa937723(v=vs.113).aspx as well)
Sep 11, 2017 06:49 PM|doubleagentj|LINK
No I really, really don't want to use entity framework. Not only is it super slow, it's conventions and ceremony are a nuisance to me.
Sep 11, 2017 09:28 PM|Lannie|LINK
You can use MySqlDataReader then walk the data reader result set into any data structure you desire (list, data grid, dictionary, etc.).
To pass data to the bind variable you are using userid, you will have to add PARAMETERS to the connection.