Now, for every model in my MVC 3 app I create data class (in separate directory) were store a code which working direct with MySQL:
public Models.Inflation Select(int id)
{
Models.Inflation inflation = new Models.Inflation();
MySqlConnection connection = new MySqlConnection(ConnectionString.ConnectionStringMySQL);
MySqlCommand command = new MySqlCommand("SELECT " +
"inflation.monthInf, " +
"inflation.indexInflation " +
"FROM " +
"inflation " +
"WHERE id=@id " +
"ORDER BY inflation.monthInf ASC",
connection);
command.Parameters.AddWithValue("@id", id);
MySqlDataReader reader = null;
try
{
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
inflation.ID = id;
inflation.Date = DateTime.Parse(reader["monthInf"].ToString());
inflation.IndexInflation = decimal.Parse(reader["indexInflation"].ToString());
}
}
catch (Exception ex)
{
}
finally
{
if (reader != null)
reader.Close();
connection.Close();
}
return inflation;
}
But this method very tedious (for every Model class I must create Select, Insert, Delete, Edit...). How to improve the development and not using Entity Framework (ORM difficult to connect in my hosting).?