Beispiel #1
0
        public void Run()
        {
            new DStudent().Add(new Student()
            {
                Name = "这不是一个事务"
            });
            using (var context = new LZHData())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    DPerson  dPerson  = new DPerson(context);
                    DStudent dStudent = new DStudent(context);

                    dPerson.Add(new Person()
                    {
                        Age = 1, FirstName = "f", LastName = "f"
                    });

                    dStudent.Add(new Student()
                    {
                        Name = "f"
                    });

                    dbContextTransaction.Commit();
                }
            }
        }
Beispiel #2
0
        public Student GetModelByID(long ID)
        {
            Student model = null;

            using (var context = new LZHData())
            {
                model = context.Student.Find(ID);
            }
            return(model);
        }
Beispiel #3
0
        /// <summary>
        /// 分页获取
        /// </summary>
        /// <param name="pageSize">页码</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="countNum">总数</param>
        /// <returns></returns>
        public IList <Student> GetList(int pageSize, int pageIndex, ref long countNum)
        {
            IList <Student> list = new List <Student>();

            using (var context = new LZHData())
            {
                var query = context.Student.OrderBy(x => x.ID).Skip(pageSize * (pageIndex - 1)).Take(pageSize);
                query = query.Where(x => x.ID > 10);


                list = query.ToList();

                countNum = context.Student.Count();
            }
            return(list);
        }
Beispiel #4
0
        public bool Add(Person person)
        {
            var flag = false;

            if (_Context == null)
            {
                using (var context = new LZHData())
                {
                    context.Person.Add(person);
                    flag = context.SaveChanges() > 0;
                }
            }
            else
            {
                _Context.Person.Add(person);
                flag = _Context.SaveChanges() > 0;
            }
            return(flag);
        }
Beispiel #5
0
        public bool Add(Student student)
        {
            var flag = false;

            if (_Context == null)
            {
                using (var context = new LZHData())
                {
                    context.Student.Add(student);
                    flag = context.SaveChanges() > 0;
                }
            }
            else
            {
                _Context.Student.Add(student);
                flag = _Context.SaveChanges() > 0;
            }
            return(flag);
        }
Beispiel #6
0
 public DPerson(LZHData context)
 {
     _Context = context;
 }
Beispiel #7
0
 public DStudent(LZHData context)
 {
     _Context = context;
 }