Open Closed

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


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)
  • 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,

  • 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, 'daniel__at__ekhartyoga.com.ey@bild-studio.net', null, 'daniel__at__ekhartyoga.com.ey@bild-studio.net', 'Daniel', 'Trout', True, 'DANIEL__AT__EKHARTYOGA.COM.EY@BILD-STUDIO.NET', 'DANIEL__AT__EKHARTYOGA.COM.EY@BILD-STUDIO.NET', '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.

  • 0
    denis.karovic created

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

  • 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