Esempio n. 1
0
        private static void TransactionTest(TeacherContext teacherContext)
        {
            var teacher = teacherContext.KeyValues.FromSql("Select Id,Name from Strudent");

            //var cnn = teacherContext.Database.GetDbConnection().
            teacherContext.Database.ExecuteSqlCommand("");
            // var tran = teacherContext.Database.BeginTransaction();
        }
Esempio n. 2
0
 private static void update(TeacherContext ctx, Teacher teach)
 {
     teach.FirstName = "نیکا";
     ctx.SaveChanges();
     teach.LastName = "After Update";
     ctx.SaveChanges();
     teach.FirstName = "پریسا";
     ctx.SaveChanges();
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            TeacherContext teacherContext = new TeacherContext();

            foreach (var item in teacherContext.Model.GetEntityTypes())
            {
            }
            Console.WriteLine("Perss any key");
            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var ctx = new TeacherContext();

            //teacherContext.Database.EnsureCreated();


            //ctx.Teachers.DeleteAllAsync();

            Console.ReadLine();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var ctx = new TeacherContext();
            //add(ctx);
            var teach = ctx.Teacher.FirstOrDefault();

            update(ctx, teach);

            Console.WriteLine("Hello World!");
            Console.ReadLine();
        }
Esempio n. 6
0
        private static void add(TeacherContext ctx)
        {
            ctx.Teacher.Add(new Teacher
            {
                FirstName = "نیکا",
                LastName  = "نیکا"
            });
            ctx.Teacher.Add(new Teacher
            {
                FirstName = "پرکیا",
                LastName  = "پریکا"
            });

            ctx.SaveChanges();
        }
Esempio n. 7
0
        private static void TestChangeTracker(TeacherContext teacherContext)
        {
            var person = teacherContext.Teachers.FirstOrDefault();

            //teacherContext.Teachers.Add(new
            //    Entities.Teacher
            //{
            //    FirstName = "Alireza",
            //    LastName = "Oroumand",
            //});
            person.FirstName = "Ali reza";
            teacherContext.SaveChanges();

            person.LastName = "Oroumand AfterUpdate";
            teacherContext.SaveChanges();
            person.FirstName = "Alireza";
            teacherContext.SaveChanges();
        }
        static void Main(string[] args)
        {
            TeacherContext teacherContext = new TeacherContext();

            //Query begirim
            //var tea = teacherContext.Teachers.FromSql("");

            //var rr = teacherContext.Database.GetDbConnection().ConnectionString;
            //command insert update
            //teacherContext.Database.ExecuteSqlCommand("");

            //teacherContext.Teachers.Load();

            //var tan = teacherContext.Database.BeginTransaction();

            foreach (var item in teacherContext.Model.GetEntityTypes())
            {
                item.Name.Trim();
            }
        }
        private static void Tracker()
        {
            TeacherContext teacherContext = new TeacherContext();

            //teacherContext.Teachers.Add(new Entites.Teacher
            //{

            //    FirstName = "Omid",
            //    LastName = "Khaleghi"
            //});
            var a = teacherContext.Teachers.FirstOrDefault();

            a.LastName = "nouri arejani";

            teacherContext.SaveChanges();
            a.FirstName = "ALi";
            teacherContext.SaveChanges();

            System.Console.WriteLine("W");

            Console.ReadLine();
        }
Esempio n. 10
0
 public TeacherTests(TeacherRepository teacherRepository, TeacherContext teacherContext)
 {
     _teacherRepository = teacherRepository;
     _dbContext         = teacherContext;
 }
Esempio n. 11
0
 public TeacherRepository(TeacherContext teacherContext)
 {
     this._teacherContext = teacherContext;
 }
Esempio n. 12
0
 public HomeController(TeacherContext ctx)
 {
     context = ctx;
 }
 public TeacherRepository(TeacherContext context)
 {
     this.context = context;
 }
Esempio n. 14
0
 public Repository(TeacherContext dbContext)
 {
     _dbContext = dbContext;
 }
 public TeacherController(TeacherContext context)
 {
     _context = context;
 }
 private static TeacherContext InitializeTeacherContext(TeacherContext context)
 {
     _teacherContext = context;
     return(_teacherContext);
 }
Esempio n. 17
0
        public static void Test()
        {
            Database.SetInitializer <TestContext>(null);
            Database.SetInitializer <TeacherContext>(null);
            using (var context = new TestContext())
            {
                context.Database.Log = Console.WriteLine;

                var sGuid1 = Guid.NewGuid().ToString();
                var sGuid2 = Guid.NewGuid().ToString();
                var tGuid1 = Guid.NewGuid().ToString();
                var tGuid2 = Guid.NewGuid().ToString();

                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Student s1 = new Student()
                        {
                            ID            = sGuid1,
                            Name          = "张萨姆",
                            StudentNumber = 1,
                            IsMale        = true
                        };

                        Student s2 = new Student()
                        {
                            ID            = sGuid2,
                            Name          = "张市长",
                            StudentNumber = 2,
                            IsMale        = false
                        };

                        Teacher t1 = new Teacher()
                        {
                            ID   = tGuid1,
                            Name = "张巨鹿"
                        };


                        Teacher t2 = new Teacher()
                        {
                            ID   = tGuid2,
                            Name = "老黄"
                        };

                        t1.Students.Add(s1);
                        t1.Students.Add(s2);
                        t2.Students.Add(s1);
                        t2.Students.Add(s2);
                        context.Entry(s1).State = EntityState.Added;
                        context.Entry(s2).State = EntityState.Added;
                        context.Entry(t1).State = EntityState.Added;
                        context.Entry(t2).State = EntityState.Added;

                        TeacherContext thContext = new TeacherContext(
                            context.Database.Connection,
                            contextOwnsConnection: false);
                        thContext.Database.UseTransaction(transaction.UnderlyingTransaction);

                        int c = context.SaveChanges();
                        Console.WriteLine("SaveChanges影响的行数:{0}", c);

                        //c = thContext.Database.ExecuteSqlCommand(" UPDATE STUDENT SET NAME=:NAME WHERE ID=:ID", new OracleParameter[]{
                        //    new OracleParameter("@NAME","东源"),
                        //    new OracleParameter("@ID",sGuid1),
                        //});
                        //Console.WriteLine("ExecuteSqlCommand影响的行数:{0}", c);

                        t1.Name = "落月";
                        //thContext.Entry(t1).Property(p => p.Name).IsModified = true;
                        thContext.Entry(t1).State = EntityState.Modified;
                        c = thContext.SaveChanges();
                        Console.WriteLine("thContext的SaveChanges影响的行数:{0}", c);

                        transaction.Commit();

                        try
                        {
                            Console.WriteLine("----------------------------学生信息-------------------------------------");

                            context.Entry(s1).Reload();
                            var studentLst = context.Students.Local;
                            Console.WriteLine(string.Format("学生的数量:{0}", studentLst.Count));
                            foreach (var s in studentLst)
                            {
                                Console.WriteLine(string.Format("ID:{0},Name:{1},Sex:{2}", s.ID, s.Name, s.IsMale));
                                foreach (Teacher tc in s.Teachers)
                                {
                                    Console.WriteLine(string.Format("学生对应的老师( -- ID:{0},姓名:{1} -- )", tc.ID, tc.Name));
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        transaction.Rollback();
                    }
                }
            }
        }
Esempio n. 18
0
 public Repository(IConnectionStringFactory connectionStringFactory, TeacherContext dbContext)
 {
     _connectionStringFactory = connectionStringFactory;
     _dbContext = dbContext;
 }
 public SubjectStateMachineTests()
 {
     _adminContext   = new CourseAdminContext(new New());
     _teacherContext = new TeacherContext(new InProgress());
 }