コード例 #1
0
        public void TestMethod1()
        {
            using (SchoolContext ctx = new SchoolContext())
            {
                ctx.Configuration.LazyLoadingEnabled = false;
                //School s1 = new School() { Name = "Coopers", Address = "Royal Parade" };
                //EntityState st1 = ctx.Entry(s1).State;
                //ctx.Schools.Add(s1);

                //ctx.SaveChanges();

                School s2 = ctx.Schools.Include(x => x.Students).Where(x => x.Id == 1).FirstOrDefault();

                EntityState st2 = ctx.Entry(s2).State;
                s2.Name = "change";
                st2 = ctx.Entry(s2).State;
            }

            using (UnitOfWork uow = new UnitOfWork())
            {
                School s1 = uow.Repository<School>().GetByID(1);

                uow.Repository<School>().Insert(new School() { Name = "Coopers", Address = "Royal Parade" });
                uow.Save();
            }
        }
コード例 #2
0
        public ActionResult Index()
        {
            var leftJoin = LINQExamplesService.LeftJoin().ToList();
            var rightJoin = LINQExamplesService.RightJoin().ToList(); // switch round the join order and use the same DefaultIfEmpty()

            var groupByQuery = LINQExamplesService.GroupByQuery().ToList();
            var groupByLambda = LINQExamplesService.GroupByLambda().ToList();

            SchoolContext _ctx = new SchoolContext();

            // GetByID uses .Find() gets from Context if there already else the DB
            School sc1 = _unitOfWork.Repository<School>().GetByID(1);
            sc1.Name = "Bromley High";

            _unitOfWork.Save();

            return View();
        }
コード例 #3
0
 public DepartmentModelBinder(SchoolContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #4
0
 public StudentController(SchoolContext db)
 {
     this.db = db;
 }
コード例 #5
0
 public InstructorModelBinder(SchoolContext dbContext)
 {
     _dbContext = dbContext;
 }