Inheritance: IAggregateRoot
Exemplo n.º 1
0
        public async Task<bool> Add(string name)
        {
            var student = new Student { Name = name };
            var teacher = await _teacherRepository.Get(1).FirstOrDefaultAsync();
            teacher.StudentCount++;

            _unitOfWork.RegisterNew(student);
            _unitOfWork.RegisterDirty(teacher);
            return await _unitOfWork.CommitAsync();
        }
Exemplo n.º 2
0
        public async Task<bool> AddWithTransaction(string name)
        {
            _unitOfWork.BeginTransaction();

            var teacher = new Teacher { Name = "teacher one" };
            await _unitOfWork.RegisterNew(teacher);

            await _unitOfWork.ExecuteSqlCommandAsync("update students set name='xishuai 2'");

            var student = new Student { Name = name, TeacherId = teacher.Id };
            await _unitOfWork.RegisterNew(student);

            return await _unitOfWork.CommitAsync();
        }