Reputation: 11
All of the examples that I have seen so far regarding db connectivity in MVC are using Entity Framework. So my question is, Is it must for db handling in MVC?
Upvotes: 1
Views: 932
Reputation: 321
No, surely it is NOT a must.
But Entity Framework is Microsoft’s recommended data access technology for new applications. And it has some very nice features. That`s why it is so pupular.
It also has some very nice features:
You can read more here: http://sqlmag.com/entity-framework/5-reasons-why-entity-framework-can-be-your-best-friend
Upvotes: 0
Reputation: 7640
No it is not a must. You can implement your database layer. But the thing you need is define Models for MVC:
public class MyClass
{
[Display(Name = "SomeName")]
[Required(ErrorMessage = "required")]
public int? SomeId { get; set; }
//...
}
for scaffolding.
Here is example implementation for Ado.net DataAdapter:
public class MyController : Controller
{
public ActionResult Index()
{
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT columns FROM sometable", @"connectionstring"))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
MyClass myClass = new MyClass();
myClass.SomeId = ConvertTo.Int32(dt.Rows[0]["myId"].ToString());
//...
return View(MyClass)
}
}
}
And the View is:
Index.chtml:
@model myProject.Models.MyClass
@Html.TextBoxFor(m=>m.SomeId)
Upvotes: 1