1

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).?

1 Answer 1

1

You can use Microsoft Enterprise libraries. And in later stage if would like to migrate from MySql to SqlServer datebase you can do this by just changing your connection string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.