C#C
C#3mo ago
69 replies
strikeouts27

Understanding how to load and retrieve information from a database using a controller using ASP.NET.

I am currently working on a project where I need to retrieve data from a database and order and sort it.


Examining the Generated Code: https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/accessing-your-models-data-from-a-controller


I have never done this before. And I have been advised to look at the documentation tutorial.

Upon reviewing it I fail to understand the process. Is Moviecontext a super object that we pass properties and abilities to it through inheritance and value assignment?

Do we use properties to assign capabilities?

And than also how is the information passed to the view and ordered?

Do we use DbSet<Entity> properties to add capabilites to the object we are trying to pass to the view?
DbContext options configure the DdbBontext object.
Textbook example
using Microsoft.EntityFrameworkCore;

namespace MovieList.Models {
  public class MovieContext : DbContext 
  {
    public MovieContext(DbContextOptions<MovieContext> options) 
      : base(options)
    { } 
    public DbSet<Movie> Movies { get; set; } = null!; 
    }
  }
 

in this example its not loading anything.
In this section, you'll create a new MoviesController class and write code that retrieves the movie data and displays it in the browser using a view template.
Accessing Your Model's Data from a New Controller
Was this page helpful?