Vipin
Vipin

Reputation: 11

Is it must to use entity framework for db handling in MVC?

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

Answers (2)

CrazyDog
CrazyDog

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:

  1. Shield Yourself From SQL
  2. Much faster to build the DAL (DATA ACCESS LAYER)
  3. Easier to mantain

You can read more here: http://sqlmag.com/entity-framework/5-reasons-why-entity-framework-can-be-your-best-friend

Upvotes: 0

asdf_enel_hak
asdf_enel_hak

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

Related Questions