1. 程式人生 > >2018.11.02 理解context 和_context.

2018.11.02 理解context 和_context.

    public class IndexModel : PageModel
    {
        private readonly ContosoUniversity.Models.SchoolContext _context;

        public IndexModel(ContosoUniversity.Models.SchoolContext context)
        {
            _context = context;
        }

        public List<Student> Student { get;set; }

        public async Task OnGetAsync()
        {
            Student = await _context.Student.OrderByDescending(x=>x.EnrollmentDate).Where (x=>x.ID.Equals("11")).ToListAsync();
        }
    }

 context 就是一個庫._context是全域性的庫.

表示式:條件篩選.