Currently to query my table of users I have to do the following in my controller.
using (MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["test_schema"].ConnectionString))
{
connection.Open();
MySqlCommand command = new MySqlCommand("SELECT * FROM users", connection);
MySqlDataReader reader = command.ExecuteReader();
List<string> users = new List<string>();
while (reader.Read())
{
users.Add(reader["id"] + "\t" + reader["first_name"]);
}
ViewBag.users = users;
reader.Close();
}
Is it possible in C# to put the results in a dynamic object similar to how ViewBag works?
I have some experience in Node.js Express and to write a query using the sequelize module all I have to do is write something like
Sequelize.query("SELECT * FROM users", { type: sequelize.QueryTypes.SELECT }).then(users => {
// users attributes will be the columns of the user table
});
I left out the part of how to connect to a database in sequelize but I don't think it is relevant to the question.