コード例 #1
0
        public static void AddStudent(FrameworkContext context)
        {
            var newStudent = new Student
            {
                name         = "Sujan",
                cgpa         = 2.9,
                MobileNumber = "01871414911",
                Address      = "Dhaka, Bangladesh"
            };

            context.Students.Add(newStudent);
            context.SaveChanges();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var connectionString      = "Server=DESKTOP-QNQ23OO;Database=CSharpHome;User Id=dipto_user;Password=1234567; ";
            var migrationAssemblyName = typeof(Program).Assembly.FullName;
            var context = new FrameworkContext(connectionString, migrationAssemblyName);
            var student = GetStudent(context, 3);

            Console.WriteLine(student.name);

            student.cgpa = 3.3;

            context.SaveChanges();

            context.Students.Remove(student);
            context.SaveChanges();
        }
コード例 #3
0
        public static void CreateCourseAndStudent(FrameworkContext context)
        {
            var course = new Course
            {
                Title = "C# Fundamental",
                Fee   = 6000,
            };
            var student = new Student
            {
                name         = "Dipto",
                MobileNumber = "01986228955",
                cgpa         = 3.2,
                Address      = "Gazipur, Bangladesh"
            };

            course.CourseStudents = new List <Student>();
            course.CourseStudents.Add(student);

            context.Courses.Add(course);
            context.SaveChanges();
        }
コード例 #4
0
        public static Student GetStudent(FrameworkContext context, int id)
        {
            var student = context.Students.Where(x => x.Id == id).FirstOrDefault();

            return(student);
        }