using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; [Table("Students")] public class Student { [Key] public int Id { get; set; } [Column("Full_Name")] public string Name { get; set; } [Required] public int Age { get; set; } }
using System.Collections.Generic; using System.Linq; public class StudentRepository { private readonly SchoolContext _context; public StudentRepository(SchoolContext context) { _context = context; } public ListHere, we have a repository class that utilises a C# Entity called "Student". We pass the context into the constructor and use the LINQ method "Where" to filter all students with a particular age. The method returns a list of student objects. Package library: Entity Framework Core.GetStudentsByAge(int age) { return _context.Students.Where(s => s.Age == age).ToList(); } }