public StudentsController()
 {
     this.db = new StudentsDbContext();
     this.students = new EfGenericRepository<Student>(this.db);
     this.homeworks = new EfGenericRepository<Homework>(this.db);
     this.courses = new EfGenericRepository<Course>(this.db);
 }
Пример #2
0
        private static void SeedData(StudentsDbContext dbContext)
        {
            var generator = new DataGenerator();

            var students = generator.GenerateStudents(10);

            var courses = generator.GenerateCourses(10);

            var index = 0;
            foreach (var student in students)
            {
                student.Courses = courses.Skip(index).ToList();
                dbContext.Students.Add(student);
            }

            dbContext.SaveChanges();
            dbContext.Dispose();

            dbContext = new StudentsDbContext();

            var homeworks = generator.GenerateHomeworks(5);
            var actualStudents = dbContext.Students.ToList();
            var actualCourses = dbContext.Courses.ToList();

            var studentsToSkip = 0;
            foreach (var homework in homeworks)
            {
                homework.Student = actualStudents.Skip(studentsToSkip).FirstOrDefault();
                homework.Course = actualCourses.Skip(studentsToSkip).FirstOrDefault();
                dbContext.Homeworks.Add(homework);
            }

            dbContext.SaveChanges();
        }
Пример #3
0
        public static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentsDbContext, Configuration>());

            var dbContext = new StudentsDbContext();

            var studentNames = dbContext.Students.Select(s => s.Name).ToList();
        }
Пример #4
0
        public static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentsDbContext, Configuration>());

            var dbContext = new StudentsDbContext();
            SeedData(dbContext);

            var studentNames = dbContext.Students.Select(s => s.Name).ToList();

            foreach (var studentName in studentNames)
            {
                Console.WriteLine(studentName);
            }

        }
Пример #5
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentsDbContext, Configuration>());

            var db = new StudentsDbContext();

            var student = new Student()
            {
                Name = "Pesho"
            };

            db.Students.Add(student);
            db.SaveChanges();

            Console.WriteLine(db.Students.Count());
        }
 public HomeworksController()
 {
     this.db = new StudentsDbContext();
     this.homeworks = new EfGenericRepository<Homework>(this.db);
 }