Ejemplo n.º 1
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<SchoolSystemDbContext, Configuration>());

            SchoolSystemDbContext schoolSystemContext = new SchoolSystemDbContext();

            schoolSystemContext
                .Students
                    .FirstOrDefault()
                    .Courses
                    .Add(new Course()
                    {
                        Name = "Testing course",
                        Description = "Just another useless course",
                    });

            schoolSystemContext.SaveChanges();

            foreach (var course in schoolSystemContext.Courses.Include("Students"))
            {
                Console.WriteLine(course.Name);
                foreach (var student in course.Students)
                {
                    Console.Write(" --> " + student.Name + " ");
                }
                Console.WriteLine();
            }

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Database.SetInitializer(new SchoolSystemDbInitializer());
            using (var db = new SchoolSystemDbContext())
            {
                db.Database.Initialize(true);                
            }
        }
 public StudentsDbRepositoryTests()
 {
     this.dbContext = new SchoolSystemDbContext();
     this.repository = new StudentsDbRepository(this.dbContext);
 }