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(); }
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(); }