Friday 29 April 2022

ASP.Net model to winhost prod database

The tutorial ASP.NET Core MVC has content:

  • Get started
  • Add a controller
  • Add a view
  • Add a model - scaffold movie pages (updates/creates files)
  • Work with a database
  • Controller actions and views
  • Add search
  • Add a new field
  • Add validation
  • Examine Details and Delete

 https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-6.0&tabs=visual-studio

Add a model

Below codes create database table based on model

Add-Migration InitialCreate

Update-Database







Make sure appsetrtings.json has correct connection string to winhost to create / update table.


After running localhost, Program.cs run code block and inserts default 4 records into database.


using (var scope = app.Services.CreateScope())

{

    var services = scope.ServiceProvider;

    SeedData.Initialize(services);

}

Add a new field 

Add-Migration Rating

Update-Database


<questions>

        private readonly MvcMovieContext _context;

q. when this context is setup?

ans. Controller >> right click >> add >> New scaffolded item ...

<next>

How to deploy

https://stackify.com/how-to-deploy-asp-net-core-to-iis/

What's ASP.NET Core?

https://stackify.com/asp-net-core-features/


Local database

Use ServerName = (LocalDb)\MSSQLLocalDB

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b75bef7e-13f3-4658-8d43-9df12ab4c320/connecting-localdb-using-sql-server-management-studio-express?forum=sqlexpress