title: How to populate a model without entity framework in Asp.net MVC 5
body: <p><strong><em>Note:- This question will arise in the mind of developer who don't have an idea about entity framework and have directly started learning asp.net MVC 5. Once you are on the road to learn a new thing it is difficult to grasp several new concept. This question will help new developer getting started with MVC straight away using their existing knowledge of Ado.net.</em></strong></p>
  
  <p>I have been trying to use asp.net MVC 5 with my existing database. I am not going to use Entity framework for populating the model. How can I populate my model without using any dbcontext. How can i fetch data from database and put inside model?
  Here is my Controller Action:- </p>
  
  <pre><code>    public ActionResult Index()
              {
                  /* WHAT TO DO HERE TO LOAD THE TRANSACTIONS? This part is resolved in following lines*/
  /* I have used following code to get it using the direct db connection */
  var transactions = new List&lt;Portal.Models.TransactionModels&gt;();
              var connectionString = "server=yourserver;database=yourdatabase;uid=youruid;pwd=yourpwd";
              MySqlConnection oMySqlConnection = new MySqlConnection(connectionString);
              oMySqlConnection.Open();
              MySqlCommand oMySqlCommand = new MySqlCommand("Select * from yourtable;", oMySqlConnection);
              MySqlDataReader oMySqlDataReader = oMySqlCommand.ExecuteReader();
              while (oMySqlDataReader.Read())
              {
                  transactions.Add(new Portal.Models.TransactionModels
                  {
                      transaction_id = oMySqlDataReader["transaction_id"].ToString()
                  });
              }
              oMySqlConnection.Close();
              return View(transactions);
  
                  return View();
              }
  </code></pre>
  
  <p>Here is my Model:-</p>
  
  <pre><code>  public class TransactionModels
      {
          public virtual string id{ get; set;}
          public virtual int statusid { get; set; }
      }
  </code></pre>
  
  <p>Here is my View:-</p>
  
  <pre><code>@model IEnumerable&lt;Portal.Models.TransactionModels&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.id)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.statusid)
          &lt;/th&gt;       
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.id)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.statusid)
          &lt;/td&gt;
  
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
              @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
              @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  </code></pre>