Esempio n. 1
0
        static void Main(string[] args)
        {
            StudentsContext context = new StudentsContext();

            context.Students.Add(new Student
            {
                Name             = "Petar",
                RegistrationDate = DateTime.Now
            });
            context.SaveChanges();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            StudentsContext context = new StudentsContext();

            Console.WriteLine("Lists of students and their homeworks:");
            var studentHomeworks = context.Students.Select(s => new
            {
                StudentName     = s.Name,
                StudentHomework = s.Homeworks
            });

            foreach (var studentHomework in studentHomeworks)
            {
                Console.WriteLine(studentHomework.StudentName);
                foreach (var studentHW in studentHomework.StudentHomework)
                {
                    int    enumValue   = (int)studentHW.ContentType;
                    string stringValue = Enum.GetName(typeof(ContentType), enumValue);
                    Console.WriteLine($"--HW-- {studentHW.Content} - {stringValue}");
                }
            }

            Console.WriteLine("All courses and their resources:");
            var coursesResources = context.Courses
                                   .OrderBy(c => c.StartDate)
                                   .ThenByDescending(c => c.EndDate)
                                   .Select(c => new
            {
                CourseName        = c.Name,
                CourseDescription = c.Description,
                Resources         = c.Resources
            });

            foreach (var coursesResource in coursesResources)
            {
                Console.WriteLine(coursesResource.CourseName + " - " + coursesResource.CourseDescription);
                foreach (var resource in coursesResource.Resources)
                {
                    Console.WriteLine($"--ResourceInfo-- {resource.Name} - {resource.URL}");
                }
            }
            context.SaveChanges();
        }