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

EF Core Repository items not tracked after insert with ExecuteSqlRaw(commandText) #9625


User avatar
0
denis.karovic created
  • Product version: 5.4
  • Product type: Angular
  • Framework type: .net core
  • ABP Framework version: 5.4.0

Hy, I am inserting data by executing raw sql command. All data are properly inserted into database, but the repository is not aware of them being inserted. Basically, usersBeforeInsert and usersAfterInsert contain the same 3 records.

Also, after application restart, repository is still not aware of users inserted with ExecuteSqlRaw(), retrieving only users that existed prior to ExecuteSqlRaw().

How to make _userRepository retrieve all data from db?

Here is the code sample:

var usersBeforeInsert = await _userRepository.GetAllListAsync(); // 3 records retrieved var commandText = GenerateInsertUsersSqlScript(users); var context = _userRepository.GetDbContext(); var rowsAffected = context.Database.ExecuteSqlRaw(commandText); // 85000 records inserted context.SaveChange(); var usersAfterInsert = await _userRepository.GetAllListAsync(); // 3 record retrieved


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @denis.karovic

    Could you also share the commandText and a sample data (just for 1 line) ? This might be related to NormalizedUsername or NormalizedEmailAddress fields.

    Thanks,

  • User Avatar
    0
    denis.karovic created

    Sure. We are using PostgreSql:

    insert into "AbpUsers" ("CreationTime", "CreatorUserId", "LastModificationTime", "LastModifierUserId", "IsDeleted", "DeleterUserId", "DeletionTime", "UserName", "TenantId", "EmailAddress", "Name", "Surname", "IsActive", "NormalizedUserName", "NormalizedEmailAddress", "ConcurrencyStamp", "ProfilePictureId", "ShouldChangePasswordOnNextLogin", "ExternalReference", "AccessFailedCount", "IsEmailConfirmed", "IsLockoutEnabled", "IsPhoneNumberConfirmed", "IsTwoFactorEnabled") values ('2018-04-13 12:25:15', null, null, null, False, null, null, '[email protected]', null, '[email protected]', 'Daniel', 'Trout', True, '[email protected]', '[email protected]', '067b0a70-288d-4206-bbdd-a4201bf872a6', null, False, 'b7abbedd-7a84-418c-adf4-039c55d8fe61', 0, false, false, false, false)

    What reaslly confuses me is that even after app restart, **await _userRepository.GetAllListAsync(); ** returns only three uses that existed prior to insertion.

  • User Avatar
    0
    denis.karovic created

    Hi, I know that you guys are probably very busy, but any news on this problem?

  • User Avatar
    0
    gterdem created
    Support Team

    Hello @denis.karovic,

    Can you try insert queries in an isolated unit of work and try again? You can check here about it: https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work