Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Two context on same db with custom repository raises error #3764


User avatar
0
ivanosw1 created

Hi, We are upgrading from AspNetZero 3.2.0 to 4.3.0 (Core + Angular). All code is migrated and compiles, but I have an error when using two context on same database. On 3.2.0 all works fine but now when is made the call on GetUserByIdAsync I've the error: The specified transaction is not associated with the current connection. Only transactions associated with the current connection may be used.

profileRepository is a custom repository. userManager is the standard SolutionName.Authorization.Users.UserManager.

public async Task<UserInfo> GetUserInfo(long id) { var user = await GetUserFromProfile(id); var profile = await GetProfile(id); UserInfo userInfo = new UserInfo(user, profile); return userInfo; }

public async Task<User> GetUserFromProfile(long profileId) { var userId = await profileRepository.GetAsync(profileId); // <- this works var result = await GetUser(userId.UserId); return result; }

public async Task<User> GetUser(long userId) { var user = await userManager.GetUserByIdAsync(userId); // <- this fails return user; }

I've looked at MultipleDbContextDemo but it isn't with EfCore.

What I have to change to resolve this issue ?

Thank you.


3 Answer(s)
  • User Avatar
    0
    bbakermmc created

    I have the same issue, its marked to be resolved in 4.4. You can set your method UoW to not be transactional to make it work for now.

    <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/372">https://github.com/aspnetzero/aspnet-ze ... issues/372</a>

  • User Avatar
    0
    ivanosw1 created

    Thank you very very much @BBakerMMC.

    In this moment there are many versions and many things to update and fix. Is difficult find if it's a bug, an error or some wrong implementations. I was looking for a solution since this morning .

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ivanosw1,

    We are still working on this issue. You can subscribe to this issue <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/372">https://github.com/aspnetzero/aspnet-ze ... issues/372</a>.

    Alternatively you can wait to upgrade until we fix this problem.

    Thanks.