コード例 #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();
        }
コード例 #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);                
            }
        }
コード例 #3
0
 public StudentsDbRepositoryTests()
 {
     this.dbContext = new SchoolSystemDbContext();
     this.repository = new StudentsDbRepository(this.dbContext);
 }