Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:14:02+00:00 2026-05-26T06:14:02+00:00

I am learning asp.net mvc and went through a great tutorial that demonstrated it.

  • 0

I am learning asp.net mvc and went through a great tutorial that demonstrated it. The tutorial also used Entity Framework.

We have our own data access class which I have to use.
I am a little bit confused as to what I need to do to bridge the gap between our class and MVC framework.
For example, in the tutorial, inside of MovieController.cs file, there is a Edit method, that looks like this:

[HttpPost]
        public ActionResult Edit(Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Entry(movie).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(movie);
        }

If I don’t use the Entity framework, what would it look like? Will I still need to use ModelState.IsValid and save the state like it’s done

db.Entry(movie).State = EntityState.Modified;

Please advise. A clearly written example of using asp.net mvc without the use of Entity framework would be great.

What I need to know is what role does state play here and whether it is mandatory to use or is it just a part of how the Entity framework operates.

I would re-write this as:

[HttpPost]
public ActionResult Edit(Movie movie)
{
    myDBObject.SaveChanges();
    return RedirectToAction("Index");

}

Where myDBObject is my custom database access object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:14:03+00:00Added an answer on May 26, 2026 at 6:14 am

    The examples you see out there where controllers use directly some data access framework such as Entity Framework are bad examples. The whole internet is polluted with such stuff. I can hardly look at it without having my eyes hurt. I consider those as bad practices. Data access should be separated and abstracted in a repository. So for example:

    public interface IMoviesRepository
    {
        Movie Get(int id);
        void Save(Movie movie);
    }
    

    then you could have some implementation of this interface using plain ADO.NET, EF, NHibernate, a remote web service call, some custom ORM or really whatever:

    public class MyCustomFrameworkMoviesRepository: IMoviesRepository
    {
        ...
    }
    

    and the controller will take this repository interface as constructor argument:

    public class MoviesController: Controller
    {
        private readonly IMoviesRepository _repository;
        public MoviesController(IMoviesRepository repository)
        {
            _repository = repository;
        }
    
        public ActionResult Index(int id)
        {
            var movie = _repository.Get(id);
            return View(movie);
        }
    
        [HttpPost]
        public ActionResult Index(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return View(movie);
            }
    
            _repository.Save(movie);
            return RedirectToAction("Success");
        }
    }
    

    and the last part is to configure your dependency injection framework to pass the correct implementation of the repository into the controller. Now as you can see the way the data is fetched is completely decoupled from the controller logic. It is the way it should be. Always try to avoid the strong coupling between the different layers of your application.

    And to answer your question about the State property : this is something completely specific to EF, seeing something like this in a controller is a really pity.

    And to bring this even further and improve it you would introduce view models. View models are classes which are specifically designed to meet the requirements of a given view. So for example Movie is a domain model. Domain models should never be directly passed to views. Controller actions should never take domain models as action arguments. You should define view models which will contain only what is required by the given view and then perform the mapping between the view models and the domain models. Frameworks such as AutoMapper make this very simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning ASP.NET MVC Framework, From some articles like this , it seems that
I am learning ASP.NET MVC now a days and I have found that most
I am currently learning ASP.NET MVC and I have followed Stephen Walther's tutorial: ASP.NET
I am learning ASP.NET MVC and Entity Framework Code First, LINQ by creating a
I am learning ASP.NET MVC and Entity Framework. After I learning from this web
I really like the MVC way and have actually enjoyed learning ASP.NET MVC (I
Where can I find a good tutorial on learning ASP.NET MVC using VB.net 2008
I am following the Nerd Dinner tutorial as I'm learning ASP.NET MVC, and I
I've been learning the ASP.NET MVC framework using the Apress book Pro ASP.NET MVC
I have been learning ASP.NET MVC in the last few months and I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.