title: ASP.NET MVC 4 project without any ORM
body: <p>I am trying to use ASP.NET MVC without EF and possibly without LINQ. To start with I created just one table/model/controller/view on basic ASP.net mvc template in VS2010(Just index page and Index method is implemented). I am currently going with try/error as all tutorials on the web are based on EF and I have an embedded c background.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li><p>Is the architecture correct?</p></li>
  <li><p>I saw repository pattern is used in some open source projects such as nearforums. What's its advantage and how does it fit into this, does it replace DAL?</p></li>
  <li><p>Should I pass datatables to view or objects representing the datatable?</p></li>
  <li><p>Can I pass more than one model to razor page? How can I list 2 different tables for example?</p></li>
  <li><p>Is it better to put all DAL code in one file?</p></li>
  </ul>
  
  <p><strong>DAL:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Data;
  using System.Configuration;
  using MySql.Data.MySqlClient;
  
  namespace MvcApplication1.Models
  {
    public class DAL
    {
      public DAL()
      { }
      public DataTable getDataTable(string tableName)
      {
        using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLConn"].ConnectionString))
        {
          using (MySqlCommand command = conn.CreateCommand())
          {
            command.CommandText = "select * from " + tableName;
            command.CommandType = CommandType.Text;
  
            conn.Open();
  
            var table = new DataTable();
            table.Load(command.ExecuteReader());
  
            return table;
          }
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>Product.cs class that represents Product table in the code:</strong></p>
  
  <pre><code>namespace MvcApplication1.Models
  {
    public class Product
    {
        public int ProductId { get; set; }
        public string Name { get; set; }
        public string Producer { get; set; }
        public int UnitPrice { get; set; }
    }
  }
  </code></pre>
  
  <p><strong>ProductController.cs</strong></p>
  
  <pre><code>namespace MvcApplication1.Controllers
  {
      public class ProductController : Controller
      {
          //
          // GET: /Product/
        DAL dal = new DAL();
          public ActionResult Index()
          {
            DataTable dt = dal.getDataTable("Product");
            Product[] products = new Product[dt.Rows.Count];
            for (int i = 0; i &lt; dt.Rows.Count; i++)
            {
              products[i] = new Product();
              products[i].ProductId = (int)dt.Rows[i]["ProductId"];
              products[i].Name = (string)dt.Rows[i]["Name"];
              products[i].Producer = (string)dt.Rows[i]["Producer"];
              products[i].UnitPrice = Decimal.ToInt32((decimal)dt.Rows[i]["UnitPrice"]);
            }
  
            return View(products);
          }
  ........
  ........
  }
  </code></pre>
  
  <p><strong>Index.cshtml:</strong></p>
  
  <pre><code>@model IEnumerable&lt;MvcApplication1.Models.Product&gt;
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  @foreach (var item in Model)
  {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.ProductId)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Name)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Producer)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.UnitPrice)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id=item.ProductId }) |
              @Html.ActionLink("Details", "Details", new { id=item.ProductId }) |
              @Html.ActionLink("Delete", "Delete", new { id=item.ProductId })
          &lt;/td&gt;
          &lt;br&gt;
      &lt;/tr&gt;
  }
  </code></pre>