Base solution for your next web application

Activities of "mmax"

<cite>gpcaretti: </cite>

  1. Play with the DB isolationLevel so that you can read dirty data.
  2. More clean: Use the Abp events. Register a method to the Committed event , Call SaveChangesAsync, that exit from your event. In this way the Commit Event will be fired for your post-commit operations.

Thanks a lot! I will try.

<cite>hikalkan: </cite> You don't need to create custom repository for that. See <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocUowSaveChanges">http://www.aspnetboilerplate.com/Pages/ ... aveChanges</a>

In my case I need custom repository. Also this repository is called from service, not from the controller. I'm trying to show you only root of the problem.

In other words I need to make a commit of transaction just after SaveChanges, not disposing the DbContext. Is that possible?

Please help me somebody!

Forgot to say, I'm using the latest Abp 1.0. Tried older versions. The same problem.

So, I need to commit the transaction on SaveChanges or after method executed (not action).

Tried to use UnitOfWork attribute and UnitOfWorkManager. Result is the same.

<cite>hikalkan: </cite> You should not create dbcontext directly, always use dependency injection. But.. in ABP you also should not inject dbcontext directly, but inject and use repository. Anyway, see this to save changes immediately: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocUowSaveChanges">http://www.aspnetboilerplate.com/Pages/ ... aveChanges</a>

CurrentUnitOfWork.SaveChanges();

I know all that and just made as simple as possible demonstration of what I'm trying to do. In a real project I have a custom repository with quite a lot of custom methods. The call of repository is locating in business logic, not in the controller... But even this super simple code is not working as I'm expecting. Ok, I tried one more simple test code using repositories and it's working the same. No immediate save, only after action is completely proccessed...

Is this logic works for you? What am I doing wrong? What else can I try?

private readonly IRepository<TestEntity> _testRepository;
public Constructor(IRepository<TestEntity> testRepository)
{	
	_testRepository = testRepository;
}

public async Task<ActionResult> TestAction()
{
	await _testRepository.InsertAsync(new TestEntity {...});
	await CurrentUnitOfWork.SaveChangesAsync();

	// nothing in db
	return Content("Done");
}

I have a similar problem. I need to insert and immediately save changes to the db. Simplest code example:

public ActionResult TestAction()
{
    using (var context = new TestDbContext())
    {
        context.TestDbSet.Add(new TestInst {...});
        context.SaveChanges();
    }

    // should be in the db now, but it's still local

    return Content("Ok");
}

In some reason it's not saving data to db after save changes was called. It's saving only after action was totally executed and page loaded. I'm tried to do the same using repository and unit of work manager, but the result is the same. Tried to add UnitOfWork attribute. Not working. How can I force save data to db? Please help! Many thanks!

Hi. I need to insert and immediately save changes to db, but for some reason there is no data in the db after saving changes. Its inserting the data only after controller was totally executed.

This is simplified example of my code:

public class Car : Entity
    {
        public string Name { get; set; }
    }
public interface ICarRepository : IRepository<Car>
    {
        Task SaveChangesAsync();
    }

    public class CarRepository : BaseRepository<Car>, ICarRepository
    {
        public CarRepository(IDbContextProvider<PropertyIntelDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public async Task SaveChangesAsync()
        {
            await Context.SaveChangesAsync();
        }
    }
public async Task<ActionResult> InsertCar()
        {
            await _carRepository.InsertAsync(new Car
            {
                Name = "test"
            });

            await _carRepository.SaveChangesAsync();

            return Content("Ok");
        }

Should be something simple. What am I doing wrong? How to force insert the data?

Showing 1 to 8 of 8 entries