เพิ่มโมเดล Movie ให้กับโปรเจ็กส์ WebApp (Visual Studio 2017)

สร้างโปรเจ็กส์แบบ WebApp (ด้วย Visual Studio 2017)

Add a model to a Razor Pages app in ASP.NET Core

สร้างโฟลเดอร์ Data
สร้างโฟลเดอร์ Data\Models
สร้างคลาส Data\Models\Movie.cs

Data\Models\Movie.cs

using System;

namespace WebApp.Data.Models
{
    public class Movie
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public DateTime ReleaseDate { get; set; }
        public string Genre { get; set; }
        public decimal Price { get; set; }
    }
}
Continue reading

เพิ่มโมเดล Movie ให้กับโปรเจ็กส์ WebApp (Visual Studio 2019)

  1. Add a data model
  2. Scaffold the movie model
  3. Initial migration

1.Add a data model

สร้างโฟลเดอร์ Models
สร้างคลาส Models\Movie.cs

Models\Movie.cs

using System;
using System.ComponentModel.DataAnnotations;

namespace RazorPagesMovie.Models
{
    public class Movie
    {
        public int ID { get; set; }
        public string Title { get; set; }

        [DataType(DataType.Date)]
        public DateTime ReleaseDate { get; set; }
        public string Genre { get; set; }
        public decimal Price { get; set; }
    }
}

The ID field is required by the database for the primary key.

Continue reading

คำสั่งของ .NET Core

  1. ตรวจสอบเวอร์ชันของ .NET Core
  2. สร้างโปรเจ็กส์ด้วยคำสั่ง dotnet new
  3. รันโปรเจ็กส์ด้วยคำสั่ง dotnet run
  4. ดู info
  5. ติดตั้ง dotnet-ef
  6. อัพเดท dotnet tool
Continue reading