Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when inserting multiple rows into the same table on SQL Server #29502

Closed
joakimriedel opened this issue Nov 8, 2022 · 34 comments · Fixed by #29565
Closed

Exception when inserting multiple rows into the same table on SQL Server #29502

joakimriedel opened this issue Nov 8, 2022 · 34 comments · Fixed by #29565
Assignees
Labels
area-save-changes area-sqlserver closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Milestone

Comments

@joakimriedel
Copy link
Contributor

joakimriedel commented Nov 8, 2022

Include your code

Beginning with EF Core 7.0 rc2 when a database entity is generated through a projection and then saved as a new entity, EF Core will throw exception due to "temporary value" of Id property.

Workaround: set Id to default before saving.

Pre-7.0 this was not necessary. If this is expected, it would be nice to add to https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes

var digests = await _context.Users
    .Select(u => new DailyDigest
    {
        User = u,
        TimeCreatedUtc = utcNow,
    })
    .ToListAsync();

foreach (var digest in digests)
{
    // next line is necessary in 7.0 rc2, was not necessary in 6.0 and below (down to 1.0 ?)
    // digest.Id = default;

    _context.DailyDigests.Add(digest);
}

await _context.SaveChangesAsync();

Include stack traces

System.InvalidOperationException: The property 'DailyDigest.Id' has a temporary value while attempting to change the entity's state to 'Unchanged'. Either set a permanent value explicitly, or ensure that the database is configured to generate values for this property.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.AcceptChanges()
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.AcceptAllChanges(IReadOnlyList`1 changedEntries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)

Include provider and version information

EF Core version: 7.0 rc2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: 7.0 rc2
Operating system: Win11
IDE: Visual Studio 2022 17.4

@ajcvickers
Copy link
Member

ajcvickers commented Nov 8, 2022

@joakimriedel I'm not able to reproduce this--see my code below. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

#nullable enable

public static class Your
{
    public static string ConnectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow";
}

public class Product
{
    public int Id { get; set; }
}

public class User
{
    public int Id { get; set; }
}

public class DailyDigest
{
    public int Id { get; set; }
    
    public User User { get; set; }
    public DateTime TimeCreatedUtc { get; set; }
}

public class SomeDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer(Your.ConnectionString)
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();

    public DbSet<User> Users { get; set; }
    public DbSet<DailyDigest> DailyDigests { get; set; }
}

public class Program
{
    public static async Task Main()
    {
        using (var context = new SomeDbContext())
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.Add(new DailyDigest { User = new() });
            context.SaveChanges();
        }
        
        using (var context = new SomeDbContext())
        {
            var utcNow = DateTime.UtcNow;

            var digests = await context.Users
                .Select(u => new DailyDigest
                {
                    User = u,
                    TimeCreatedUtc = utcNow,
                })
                .ToListAsync();

            foreach (var digest in digests)
            {
                // next line is necessary in 7.0 rc2, was not necessary in 6.0 and below (down to 1.0 ?)
                // digest.Id = default;

                context.DailyDigests.Add(digest);
            }

            await context.SaveChangesAsync();
        }
    }
}

@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 8, 2022

@ajcvickers I'm terribly sorry for posting a bad issue without repro.

The real project is a huge codebase, five years old and iterated on since the very first version of EF Core, which makes it quite challenging to break parts out in a smaller project and still reproduce. This issue was the only thing (except how hard it was to regenerate compiled model) that I had after migrating from 6.0.10 to 7.0-rc2 (which in itself is amazing! 🙌). I've now spent the last hours trying to reproduce in a smaller project, but without success.

It really bugs me because there is absolutely nothing I can think of in the code that might set or alter Id in any way, I simply generate DailyDigest object in the projection, set Email property on it in a loop (after generating an email), and then save it to database. But still I have to set Id manually to default int to make it work in 7.0-rc2.

Note that your sample has one issue, since it projects from Users it's necessary to have at least one User in the database:

// old: context.Add(new DailyDigest { User = new() });
context.Add(new User());

What I've applied from real project so far that I thought might help reproduce;

  • import most of the real entities and their configuration (index, keys etc)
  • enabled compiled model (dotnet ef dbcontext optimize)
  • explicitly set single query splitting mode (sqlOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery))
  • apply HierarchyId extension
  • configure conventions (utc, dateonly)
  • apply TPH (DailyDigest is derived from abstract class)
  • use more of the real query (see below)
            var digests = await context.Users
                .TagWith(tag: nameof(DailyDigest))
                // lots of conditions
                .Where(conditions...)
                .OrderBy(u => u.TimeCreatedUtc)
                .Take(maxCount)
                .Select(u => new
                {
                    User = u,
                    // lots of other calculated properties from navigation properties..
                })
                .Select(source => new DailyDigest
                {
                    User = source.User,
                    TimeCreatedUtc = utcNow,
                    // lots of other properties...
                })
                .ToListAsync(cancellationToken);

What I haven't tried so far, but might affect results;

  • run in background thread (real project use Hangfire to schedule generating daily digests)
  • use real database to get more data in query

I'd appreciate any tips or hints on what was changed in 7.0 that you think might affect migrating from 6.0.

@ajcvickers
Copy link
Member

@joakimriedel Have you tried with 7.0 GA?

@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 9, 2022

@ajcvickers Just installed 7.0 GA but this bug still reproduces in real project. I think there's something really fishy going on, perhaps memory corruption or bad caching somewhere? Look at the following verbose logs;

Verbose log
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482408' to '82477' for entity with key '{Id: 82477}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482420' to '82465' for entity with key '{Id: 82465}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482432' to '82453' for entity with key '{Id: 82453}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482403' to '82482' for entity with key '{Id: 82482}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482406' to '82479' for entity with key '{Id: 82479}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482421' to '82464' for entity with key '{Id: 82464}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482407' to '82478' for entity with key '{Id: 82478}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482423' to '82462' for entity with key '{Id: 82462}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482426' to '82459' for entity with key '{Id: 82459}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482424' to '82461' for entity with key '{Id: 82461}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482414' to '82471' for entity with key '{Id: 82471}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482431' to '82454' for entity with key '{Id: 82454}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482416' to '82469' for entity with key '{Id: 82469}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482400' to '82485' for entity with key '{Id: 82485}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482413' to '82472' for entity with key '{Id: 82472}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482418' to '82467' for entity with key '{Id: 82467}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482428' to '82457' for entity with key '{Id: 82457}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482405' to '82480' for entity with key '{Id: 82480}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482410' to '82475' for entity with key '{Id: 82475}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482427' to '82458' for entity with key '{Id: 82458}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482401' to '82484' for entity with key '{Id: 82484}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482402' to '82483' for entity with key '{Id: 82483}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482419' to '82466' for entity with key '{Id: 82466}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482409' to '82476' for entity with key '{Id: 82476}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482429' to '82456' for entity with key '{Id: 82456}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482411' to '82474' for entity with key '{Id: 82474}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482417' to '82468' for entity with key '{Id: 82468}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482422' to '82463' for entity with key '{Id: 82463}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482415' to '82470' for entity with key '{Id: 82470}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482430' to '82455' for entity with key '{Id: 82455}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482412' to '82473' for entity with key '{Id: 82473}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482404' to '82481' for entity with key '{Id: 82481}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '82485' to '82460' for entity with key '{Id: 82460}'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Closing data reader to 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: A data reader for 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' is being disposed after spending 105ms reading results.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Closing connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Closed connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' (2ms).
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82469}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82468}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82467}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82466}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82465}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82464}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82463}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82462}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82461}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.Update: Error: An exception occurred in the database while saving changes for context type 'WebApp.Data.ApplicationDbContext'.
System.InvalidOperationException: The property 'DailyDigest.Id' has a temporary value while attempting to change the entity's state to 'Unchanged'. Either set a permanent value explicitly, or ensure that the database is configured to generate values for this property.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.AcceptChanges()
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.AcceptAllChanges(IReadOnlyList`1 changedEntries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)

This line is especially troubling since Id 82485 has already been set earlier, why does it change into 82460?

Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '82485' to '82460' for entity with key '{Id: 82460}'.

Looks like it is when this entity is about to switch from Added to Unchanged that this exception is thrown.

Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82461}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
    --- I guess this is where 82460 tries to change state since it goes in descending order, see full log above ----
Microsoft.EntityFrameworkCore.Update: Error: An exception occurred in the database while saving changes for context type 'WebApp.Data.ApplicationDbContext'.

The DailyDigests will be generated in batches, default batch size is 50. If I change batch size to 1 the bug does not reproduce. It seems only as if I can reproduce this if SaveChangesAsync is called for a large number of items saved to db at once.

@joakimriedel
Copy link
Contributor Author

@ajcvickers while on the topic of logs, I noted that the following log message seems to have reversed property and class name in output string?

Microsoft.EntityFrameworkCore.ChangeTracking: Debug: Context 'ApplicationDbContext' started tracking 'DailyDigest' entity with key '{Id: -2147482447}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: 'ApplicationDbContext' generated temporary value '-2147482446' for the property 'Id.DailyDigest'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: 'ApplicationDbContext' generated value 'DailyDigest' for the property 'Kind.DailyDigest'.

Should be DailyDigest.Id not Id.DailyDigest right?

@ajcvickers
Copy link
Member

@roji Looks like this could be a batching issue related to #28654 and #29356.

@joakimriedel Can you post the SQL generated for the SaveChanges that is being executed when the exception is thrown?

@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 9, 2022

@ajcvickers Sure, this is the full log produced when executing the SaveChangesAsync call.

It does indeed look related to batching. I save 50 items here, but somehow it was decided to split into 42 in one batch and 8 in second, and the error seems to occur with the id of the item on the boundary between the two batches.

Full log output
Microsoft.EntityFrameworkCore.Update: Debug: SaveChanges starting for 'ApplicationDbContext'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Closing data reader to 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: DetectChanges starting for 'ApplicationDbContext'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: A data reader for 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' is being disposed after spending 3848ms reading results.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Closing connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Closed connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' (2ms).
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: DetectChanges completed for 'ApplicationDbContext'.
Microsoft.EntityFrameworkCore.Update: Debug: Executing 42 update commands as a batch.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Opening connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Opened connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Transaction: Debug: Beginning transaction with isolation level 'Unspecified'.
Microsoft.EntityFrameworkCore.Database.Transaction: Debug: Began transaction with isolation level 'ReadCommitted'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Creating DbCommand for 'ExecuteReader'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Created DbCommand for 'ExecuteReader' (2ms).
Microsoft.EntityFrameworkCore.Database.Command: Debug: Initialized DbCommand for 'ExecuteReader' (5ms).
Microsoft.EntityFrameworkCore.Database.Command: Debug: Executing DbCommand [Parameters=[@p0=NULL (DbType = Int32), @p1=NULL (DbType = Int32), @p2='0' (Nullable = true), @p3='5', @p4='0' (Nullable = true), @p5='0' (Nullable = true), @p6=NULL (DbType = Int32), @p7='2022-11-09T14:55:22.8900877', @p8=NULL (DbType = DateTime2), @p9='90b7bb91-9a24-42cd-8637-8839968a5f08' (Size = 450), @p10=NULL (DbType = Int32), @p11=NULL (DbType = Int32), @p12='0' (Nullable = true), @p13='5', @p14='0' (Nullable = true), @p15='0' (Nullable = true), @p16=NULL (DbType = Int32), @p17='2022-11-09T14:55:22.8900877', @p18=NULL (DbType = DateTime2), @p19='130e71fc-a1af-4ec4-889a-b9075e2c4451' (Size = 450), @p20=NULL (DbType = Int32), @p21=NULL (DbType = Int32), @p22='0' (Nullable = true), @p23='5', @p24='0' (Nullable = true), @p25='0' (Nullable = true), @p26=NULL (DbType = Int32), @p27='2022-11-09T14:55:22.8900877', @p28=NULL (DbType = DateTime2), @p29='57b7800e-f70c-456e-81c1-450a255f50b2' (Size = 450), @p30=NULL (DbType = Int32), @p31=NULL (DbType = Int32), @p32='0' (Nullable = true), @p33='5', @p34='0' (Nullable = true), @p35='0' (Nullable = true), @p36=NULL (DbType = Int32), @p37='2022-11-09T14:55:22.8900877', @p38=NULL (DbType = DateTime2), @p39='aeb1f07b-19b3-4d34-90e9-7822c7a3a0ca' (Size = 450), @p40=NULL (DbType = Int32), @p41=NULL (DbType = Int32), @p42='0' (Nullable = true), @p43='5', @p44='0' (Nullable = true), @p45='0' (Nullable = true), @p46=NULL (DbType = Int32), @p47='2022-11-09T14:55:22.8900877', @p48=NULL (DbType = DateTime2), @p49='89d138f2-da36-4ca7-9ccd-157a021193e0' (Size = 450), @p50=NULL (DbType = Int32), @p51=NULL (DbType = Int32), @p52='0' (Nullable = true), @p53='5', @p54='0' (Nullable = true), @p55='0' (Nullable = true), @p56=NULL (DbType = Int32), @p57='2022-11-09T14:55:22.8900877', @p58=NULL (DbType = DateTime2), @p59='b71d8e70-eb1c-4b77-866e-fd53b8d64d02' (Size = 450), @p60=NULL (DbType = Int32), @p61=NULL (DbType = Int32), @p62='0' (Nullable = true), @p63='5', @p64='0' (Nullable = true), @p65='0' (Nullable = true), @p66=NULL (DbType = Int32), @p67='2022-11-09T14:55:22.8900877', @p68=NULL (DbType = DateTime2), @p69='e892bd98-196e-430c-b805-d8cc2130e27b' (Size = 450), @p70=NULL (DbType = Int32), @p71=NULL (DbType = Int32), @p72='0' (Nullable = true), @p73='5', @p74='0' (Nullable = true), @p75='0' (Nullable = true), @p76=NULL (DbType = Int32), @p77='2022-11-09T14:55:22.8900877', @p78=NULL (DbType = DateTime2), @p79='ae6f55e7-db48-4c35-981a-8cbec93c9b78' (Size = 450), @p80=NULL (DbType = Int32), @p81=NULL (DbType = Int32), @p82='0' (Nullable = true), @p83='5', @p84='0' (Nullable = true), @p85='0' (Nullable = true), @p86=NULL (DbType = Int32), @p87='2022-11-09T14:55:22.8900877', @p88=NULL (DbType = DateTime2), @p89='cbb3a5d9-e9a9-450e-9026-aece053bee36' (Size = 450), @p90=NULL (DbType = Int32), @p91=NULL (DbType = Int32), @p92='0' (Nullable = true), @p93='5', @p94='0' (Nullable = true), @p95='0' (Nullable = true), @p96=NULL (DbType = Int32), @p97='2022-11-09T14:55:22.8900877', @p98=NULL (DbType = DateTime2), @p99='7a286685-3e64-485a-911c-90636e19fa85' (Size = 450), @p100=NULL (DbType = Int32), @p101=NULL (DbType = Int32), @p102='0' (Nullable = true), @p103='5', @p104='0' (Nullable = true), @p105='0' (Nullable = true), @p106=NULL (DbType = Int32), @p107='2022-11-09T14:55:22.8900877', @p108=NULL (DbType = DateTime2), @p109='3300efe5-139a-4164-94a7-72a432dada33' (Size = 450), @p110=NULL (DbType = Int32), @p111=NULL (DbType = Int32), @p112='0' (Nullable = true), @p113='5', @p114='0' (Nullable = true), @p115='0' (Nullable = true), @p116=NULL (DbType = Int32), @p117='2022-11-09T14:55:22.8900877', @p118=NULL (DbType = DateTime2), @p119='5f0b6cf8-0fe3-4236-af16-cdce6ba64228' (Size = 450), @p120=NULL (DbType = Int32), @p121=NULL (DbType = Int32), @p122='0' (Nullable = true), @p123='5', @p124='0' (Nullable = true), @p125='0' (Nullable = true), @p126=NULL (DbType = Int32), @p127='2022-11-09T14:55:22.8900877', @p128=NULL (DbType = DateTime2), @p129='8ff71738-4de1-442a-b6c3-c7d64a6792da' (Size = 450), @p130=NULL (DbType = Int32), @p131=NULL (DbType = Int32), @p132='0' (Nullable = true), @p133='5', @p134='0' (Nullable = true), @p135='0' (Nullable = true), @p136=NULL (DbType = Int32), @p137='2022-11-09T14:55:22.8900877', @p138=NULL (DbType = DateTime2), @p139='76b35648-2a76-42de-8aae-e780add568a0' (Size = 450), @p140=NULL (DbType = Int32), @p141=NULL (DbType = Int32), @p142='0' (Nullable = true), @p143='5', @p144='0' (Nullable = true), @p145='0' (Nullable = true), @p146=NULL (DbType = Int32), @p147='2022-11-09T14:55:22.8900877', @p148=NULL (DbType = DateTime2), @p149='8883df37-8c65-4a3f-b5f3-d488a2363ea4' (Size = 450), @p150=NULL (DbType = Int32), @p151=NULL (DbType = Int32), @p152='0' (Nullable = true), @p153='5', @p154='0' (Nullable = true), @p155='0' (Nullable = true), @p156=NULL (DbType = Int32), @p157='2022-11-09T14:55:22.8900877', @p158=NULL (DbType = DateTime2), @p159='315daed1-4855-4166-9ea3-5964907e8f16' (Size = 450), @p160=NULL (DbType = Int32), @p161=NULL (DbType = Int32), @p162='0' (Nullable = true), @p163='5', @p164='0' (Nullable = true), @p165='0' (Nullable = true), @p166=NULL (DbType = Int32), @p167='2022-11-09T14:55:22.8900877', @p168=NULL (DbType = DateTime2), @p169='00b18a32-b58e-417a-9cda-41f14c6a9a47' (Size = 450), @p170=NULL (DbType = Int32), @p171=NULL (DbType = Int32), @p172='0' (Nullable = true), @p173='5', @p174='0' (Nullable = true), @p175='0' (Nullable = true), @p176=NULL (DbType = Int32), @p177='2022-11-09T14:55:22.8900877', @p178=NULL (DbType = DateTime2), @p179='1057fe5d-5ed9-4e97-a6c3-a6ca73a32d7f' (Size = 450), @p180=NULL (DbType = Int32), @p181=NULL (DbType = Int32), @p182='0' (Nullable = true), @p183='5', @p184='0' (Nullable = true), @p185='0' (Nullable = true), @p186=NULL (DbType = Int32), @p187='2022-11-09T14:55:22.8900877', @p188=NULL (DbType = DateTime2), @p189='af71f453-c6b8-42f0-b0b4-6dce3b5847ec' (Size = 450), @p190=NULL (DbType = Int32), @p191=NULL (DbType = Int32), @p192='0' (Nullable = true), @p193='5', @p194='0' (Nullable = true), @p195='0' (Nullable = true), @p196=NULL (DbType = Int32), @p197='2022-11-09T14:55:22.8900877', @p198=NULL (DbType = DateTime2), @p199='1f72e993-2beb-4d8e-8386-f82b61c1a84e' (Size = 450), @p200=NULL (DbType = Int32), @p201=NULL (DbType = Int32), @p202='0' (Nullable = true), @p203='5', @p204='0' (Nullable = true), @p205='0' (Nullable = true), @p206=NULL (DbType = Int32), @p207='2022-11-09T14:55:22.8900877', @p208=NULL (DbType = DateTime2), @p209='9687efbc-2cb3-44d9-9819-720aac6361ef' (Size = 450), @p210=NULL (DbType = Int32), @p211=NULL (DbType = Int32), @p212='0' (Nullable = true), @p213='5', @p214='0' (Nullable = true), @p215='0' (Nullable = true), @p216=NULL (DbType = Int32), @p217='2022-11-09T14:55:22.8900877', @p218=NULL (DbType = DateTime2), @p219='6020039f-7349-405a-8968-add60fa8dd0f' (Size = 450), @p220=NULL (DbType = Int32), @p221=NULL (DbType = Int32), @p222='0' (Nullable = true), @p223='5', @p224='0' (Nullable = true), @p225='0' (Nullable = true), @p226=NULL (DbType = Int32), @p227='2022-11-09T14:55:22.8900877', @p228=NULL (DbType = DateTime2), @p229='57fbf1d3-b8d6-4ac2-b08f-876eac6a0dcb' (Size = 450), @p230=NULL (DbType = Int32), @p231=NULL (DbType = Int32), @p232='0' (Nullable = true), @p233='5', @p234='0' (Nullable = true), @p235='0' (Nullable = true), @p236=NULL (DbType = Int32), @p237='2022-11-09T14:55:22.8900877', @p238=NULL (DbType = DateTime2), @p239='f2bf55dc-4bba-437a-9dcd-f899a608e273' (Size = 450), @p240=NULL (DbType = Int32), @p241=NULL (DbType = Int32), @p242='0' (Nullable = true), @p243='5', @p244='0' (Nullable = true), @p245='0' (Nullable = true), @p246=NULL (DbType = Int32), @p247='2022-11-09T14:55:22.8900877', @p248=NULL (DbType = DateTime2), @p249='74570ede-c128-4a7d-ab93-287443480105' (Size = 450), @p250=NULL (DbType = Int32), @p251=NULL (DbType = Int32), @p252='0' (Nullable = true), @p253='5', @p254='0' (Nullable = true), @p255='0' (Nullable = true), @p256=NULL (DbType = Int32), @p257='2022-11-09T14:55:22.8900877', @p258=NULL (DbType = DateTime2), @p259='fc94704c-c3bb-43ad-aafc-560f4d0ee591' (Size = 450), @p260=NULL (DbType = Int32), @p261=NULL (DbType = Int32), @p262='0' (Nullable = true), @p263='5', @p264='0' (Nullable = true), @p265='0' (Nullable = true), @p266=NULL (DbType = Int32), @p267='2022-11-09T14:55:22.8900877', @p268=NULL (DbType = DateTime2), @p269='e81441c5-e084-41b9-8240-c666ca30b85f' (Size = 450), @p270=NULL (DbType = Int32), @p271=NULL (DbType = Int32), @p272='0' (Nullable = true), @p273='5', @p274='0' (Nullable = true), @p275='0' (Nullable = true), @p276=NULL (DbType = Int32), @p277='2022-11-09T14:55:22.8900877', @p278=NULL (DbType = DateTime2), @p279='969f492e-b8c4-4714-9f7c-f175cbd2b38a' (Size = 450), @p280=NULL (DbType = Int32), @p281=NULL (DbType = Int32), @p282='0' (Nullable = true), @p283='5', @p284='0' (Nullable = true), @p285='0' (Nullable = true), @p286=NULL (DbType = Int32), @p287='2022-11-09T14:55:22.8900877', @p288=NULL (DbType = DateTime2), @p289='f4ddf2da-ce69-418b-8e52-2c3a09191565' (Size = 450), @p290=NULL (DbType = Int32), @p291=NULL (DbType = Int32), @p292='0' (Nullable = true), @p293='5', @p294='0' (Nullable = true), @p295='0' (Nullable = true), @p296=NULL (DbType = Int32), @p297='2022-11-09T14:55:22.8900877', @p298=NULL (DbType = DateTime2), @p299='1bba624a-cc29-42ff-bcdc-9d2f1cb7cf07' (Size = 450), @p300=NULL (DbType = Int32), @p301=NULL (DbType = Int32), @p302='0' (Nullable = true), @p303='5', @p304='0' (Nullable = true), @p305='0' (Nullable = true), @p306=NULL (DbType = Int32), @p307='2022-11-09T14:55:22.8900877', @p308=NULL (DbType = DateTime2), @p309='8ebcaf53-f660-491a-ae3c-364c717f1359' (Size = 450), @p310=NULL (DbType = Int32), @p311=NULL (DbType = Int32), @p312='0' (Nullable = true), @p313='5', @p314='0' (Nullable = true), @p315='0' (Nullable = true), @p316=NULL (DbType = Int32), @p317='2022-11-09T14:55:22.8900877', @p318=NULL (DbType = DateTime2), @p319='e93cf5e7-a042-4ad6-a012-fb3dbb053f8e' (Size = 450), @p320=NULL (DbType = Int32), @p321=NULL (DbType = Int32), @p322='0' (Nullable = true), @p323='5', @p324='0' (Nullable = true), @p325='0' (Nullable = true), @p326=NULL (DbType = Int32), @p327='2022-11-09T14:55:22.8900877', @p328=NULL (DbType = DateTime2), @p329='0927304a-371e-4e6f-a963-04c1a0d165f5' (Size = 450), @p330=NULL (DbType = Int32), @p331=NULL (DbType = Int32), @p332='0' (Nullable = true), @p333='5', @p334='0' (Nullable = true), @p335='0' (Nullable = true), @p336=NULL (DbType = Int32), @p337='2022-11-09T14:55:22.8900877', @p338=NULL (DbType = DateTime2), @p339='da3a6162-359e-4b8e-91be-286293ebb2a0' (Size = 450), @p340=NULL (DbType = Int32), @p341=NULL (DbType = Int32), @p342='0' (Nullable = true), @p343='5', @p344='0' (Nullable = true), @p345='0' (Nullable = true), @p346=NULL (DbType = Int32), @p347='2022-11-09T14:55:22.8900877', @p348=NULL (DbType = DateTime2), @p349='628a5003-4e1f-4f45-8331-f0896432c83a' (Size = 450), @p350=NULL (DbType = Int32), @p351=NULL (DbType = Int32), @p352='0' (Nullable = true), @p353='5', @p354='0' (Nullable = true), @p355='0' (Nullable = true), @p356=NULL (DbType = Int32), @p357='2022-11-09T14:55:22.8900877', @p358=NULL (DbType = DateTime2), @p359='2d427c56-0d2d-44c8-a1e9-eeced1a4a757' (Size = 450), @p360=NULL (DbType = Int32), @p361=NULL (DbType = Int32), @p362='0' (Nullable = true), @p363='5', @p364='0' (Nullable = true), @p365='0' (Nullable = true), @p366=NULL (DbType = Int32), @p367='2022-11-09T14:55:22.8900877', @p368=NULL (DbType = DateTime2), @p369='c7a14338-42b4-4b1d-ab2a-b95562ac65a8' (Size = 450), @p370=NULL (DbType = Int32), @p371=NULL (DbType = Int32), @p372='0' (Nullable = true), @p373='5', @p374='0' (Nullable = true), @p375='0' (Nullable = true), @p376=NULL (DbType = Int32), @p377='2022-11-09T14:55:22.8900877', @p378=NULL (DbType = DateTime2), @p379='fef8e766-b586-4a1b-99e5-e33ef58284a5' (Size = 450), @p380=NULL (DbType = Int32), @p381=NULL (DbType = Int32), @p382='0' (Nullable = true), @p383='5', @p384='0' (Nullable = true), @p385='0' (Nullable = true), @p386=NULL (DbType = Int32), @p387='2022-11-09T14:55:22.8900877', @p388=NULL (DbType = DateTime2), @p389='da8d5041-81cb-49da-a208-749ef92434c5' (Size = 450), @p390=NULL (DbType = Int32), @p391=NULL (DbType = Int32), @p392='0' (Nullable = true), @p393='5', @p394='0' (Nullable = true), @p395='0' (Nullable = true), @p396=NULL (DbType = Int32), @p397='2022-11-09T14:55:22.8900877', @p398=NULL (DbType = DateTime2), @p399='2b6e0e3a-cb46-4d36-bd87-b283d710805c' (Size = 450), @p400=NULL (DbType = Int32), @p401=NULL (DbType = Int32), @p402='0' (Nullable = true), @p403='5', @p404='0' (Nullable = true), @p405='0' (Nullable = true), @p406=NULL (DbType = Int32), @p407='2022-11-09T14:55:22.8900877', @p408=NULL (DbType = DateTime2), @p409='7fbd5874-7132-44bc-9b5f-830971bc415f' (Size = 450), @p410=NULL (DbType = Int32), @p411=NULL (DbType = Int32), @p412='0' (Nullable = true), @p413='5', @p414='0' (Nullable = true), @p415='0' (Nullable = true), @p416=NULL (DbType = Int32), @p417='2022-11-09T14:55:22.8900877', @p418=NULL (DbType = DateTime2), @p419='dded04ee-7db6-4031-b7ae-cb7632863040' (Size = 450)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
MERGE [Notifications] USING (
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, 0),
(@p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, 1),
(@p20, @p21, @p22, @p23, @p24, @p25, @p26, @p27, @p28, @p29, 2),
(@p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39, 3),
(@p40, @p41, @p42, @p43, @p44, @p45, @p46, @p47, @p48, @p49, 4),
(@p50, @p51, @p52, @p53, @p54, @p55, @p56, @p57, @p58, @p59, 5),
(@p60, @p61, @p62, @p63, @p64, @p65, @p66, @p67, @p68, @p69, 6),
(@p70, @p71, @p72, @p73, @p74, @p75, @p76, @p77, @p78, @p79, 7),
(@p80, @p81, @p82, @p83, @p84, @p85, @p86, @p87, @p88, @p89, 8),
(@p90, @p91, @p92, @p93, @p94, @p95, @p96, @p97, @p98, @p99, 9),
(@p100, @p101, @p102, @p103, @p104, @p105, @p106, @p107, @p108, @p109, 10),
(@p110, @p111, @p112, @p113, @p114, @p115, @p116, @p117, @p118, @p119, 11),
(@p120, @p121, @p122, @p123, @p124, @p125, @p126, @p127, @p128, @p129, 12),
(@p130, @p131, @p132, @p133, @p134, @p135, @p136, @p137, @p138, @p139, 13),
(@p140, @p141, @p142, @p143, @p144, @p145, @p146, @p147, @p148, @p149, 14),
(@p150, @p151, @p152, @p153, @p154, @p155, @p156, @p157, @p158, @p159, 15),
(@p160, @p161, @p162, @p163, @p164, @p165, @p166, @p167, @p168, @p169, 16),
(@p170, @p171, @p172, @p173, @p174, @p175, @p176, @p177, @p178, @p179, 17),
(@p180, @p181, @p182, @p183, @p184, @p185, @p186, @p187, @p188, @p189, 18),
(@p190, @p191, @p192, @p193, @p194, @p195, @p196, @p197, @p198, @p199, 19),
(@p200, @p201, @p202, @p203, @p204, @p205, @p206, @p207, @p208, @p209, 20),
(@p210, @p211, @p212, @p213, @p214, @p215, @p216, @p217, @p218, @p219, 21),
(@p220, @p221, @p222, @p223, @p224, @p225, @p226, @p227, @p228, @p229, 22),
(@p230, @p231, @p232, @p233, @p234, @p235, @p236, @p237, @p238, @p239, 23),
(@p240, @p241, @p242, @p243, @p244, @p245, @p246, @p247, @p248, @p249, 24),
(@p250, @p251, @p252, @p253, @p254, @p255, @p256, @p257, @p258, @p259, 25),
(@p260, @p261, @p262, @p263, @p264, @p265, @p266, @p267, @p268, @p269, 26),
(@p270, @p271, @p272, @p273, @p274, @p275, @p276, @p277, @p278, @p279, 27),
(@p280, @p281, @p282, @p283, @p284, @p285, @p286, @p287, @p288, @p289, 28),
(@p290, @p291, @p292, @p293, @p294, @p295, @p296, @p297, @p298, @p299, 29),
(@p300, @p301, @p302, @p303, @p304, @p305, @p306, @p307, @p308, @p309, 30),
(@p310, @p311, @p312, @p313, @p314, @p315, @p316, @p317, @p318, @p319, 31),
(@p320, @p321, @p322, @p323, @p324, @p325, @p326, @p327, @p328, @p329, 32),
(@p330, @p331, @p332, @p333, @p334, @p335, @p336, @p337, @p338, @p339, 33),
(@p340, @p341, @p342, @p343, @p344, @p345, @p346, @p347, @p348, @p349, 34),
(@p350, @p351, @p352, @p353, @p354, @p355, @p356, @p357, @p358, @p359, 35),
(@p360, @p361, @p362, @p363, @p364, @p365, @p366, @p367, @p368, @p369, 36),
(@p370, @p371, @p372, @p373, @p374, @p375, @p376, @p377, @p378, @p379, 37),
(@p380, @p381, @p382, @p383, @p384, @p385, @p386, @p387, @p388, @p389, 38),
(@p390, @p391, @p392, @p393, @p394, @p395, @p396, @p397, @p398, @p399, 39),
(@p400, @p401, @p402, @p403, @p404, @p405, @p406, @p407, @p408, @p409, 40),
(@p410, @p411, @p412, @p413, @p414, @p415, @p416, @p417, @p418, @p419, 41)) AS i ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId], _Position) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId])
VALUES (i.[ContactId], i.[EmailMessageId], i.[InvestorsUnanswered], i.[Kind], i.[MessagesUnread], i.[OffersUnanswered], i.[SmsMessageId], i.[TimeCreatedUtc], i.[TimeDismissedUtc], i.[UserId])
OUTPUT INSERTED.[Id], i._Position;
Microsoft.EntityFrameworkCore.Database.Command: Information: Executed DbCommand (63ms) [Parameters=[@p0=NULL (DbType = Int32), @p1=NULL (DbType = Int32), @p2='0' (Nullable = true), @p3='5', @p4='0' (Nullable = true), @p5='0' (Nullable = true), @p6=NULL (DbType = Int32), @p7='2022-11-09T14:55:22.8900877', @p8=NULL (DbType = DateTime2), @p9='90b7bb91-9a24-42cd-8637-8839968a5f08' (Size = 450), @p10=NULL (DbType = Int32), @p11=NULL (DbType = Int32), @p12='0' (Nullable = true), @p13='5', @p14='0' (Nullable = true), @p15='0' (Nullable = true), @p16=NULL (DbType = Int32), @p17='2022-11-09T14:55:22.8900877', @p18=NULL (DbType = DateTime2), @p19='130e71fc-a1af-4ec4-889a-b9075e2c4451' (Size = 450), @p20=NULL (DbType = Int32), @p21=NULL (DbType = Int32), @p22='0' (Nullable = true), @p23='5', @p24='0' (Nullable = true), @p25='0' (Nullable = true), @p26=NULL (DbType = Int32), @p27='2022-11-09T14:55:22.8900877', @p28=NULL (DbType = DateTime2), @p29='57b7800e-f70c-456e-81c1-450a255f50b2' (Size = 450), @p30=NULL (DbType = Int32), @p31=NULL (DbType = Int32), @p32='0' (Nullable = true), @p33='5', @p34='0' (Nullable = true), @p35='0' (Nullable = true), @p36=NULL (DbType = Int32), @p37='2022-11-09T14:55:22.8900877', @p38=NULL (DbType = DateTime2), @p39='aeb1f07b-19b3-4d34-90e9-7822c7a3a0ca' (Size = 450), @p40=NULL (DbType = Int32), @p41=NULL (DbType = Int32), @p42='0' (Nullable = true), @p43='5', @p44='0' (Nullable = true), @p45='0' (Nullable = true), @p46=NULL (DbType = Int32), @p47='2022-11-09T14:55:22.8900877', @p48=NULL (DbType = DateTime2), @p49='89d138f2-da36-4ca7-9ccd-157a021193e0' (Size = 450), @p50=NULL (DbType = Int32), @p51=NULL (DbType = Int32), @p52='0' (Nullable = true), @p53='5', @p54='0' (Nullable = true), @p55='0' (Nullable = true), @p56=NULL (DbType = Int32), @p57='2022-11-09T14:55:22.8900877', @p58=NULL (DbType = DateTime2), @p59='b71d8e70-eb1c-4b77-866e-fd53b8d64d02' (Size = 450), @p60=NULL (DbType = Int32), @p61=NULL (DbType = Int32), @p62='0' (Nullable = true), @p63='5', @p64='0' (Nullable = true), @p65='0' (Nullable = true), @p66=NULL (DbType = Int32), @p67='2022-11-09T14:55:22.8900877', @p68=NULL (DbType = DateTime2), @p69='e892bd98-196e-430c-b805-d8cc2130e27b' (Size = 450), @p70=NULL (DbType = Int32), @p71=NULL (DbType = Int32), @p72='0' (Nullable = true), @p73='5', @p74='0' (Nullable = true), @p75='0' (Nullable = true), @p76=NULL (DbType = Int32), @p77='2022-11-09T14:55:22.8900877', @p78=NULL (DbType = DateTime2), @p79='ae6f55e7-db48-4c35-981a-8cbec93c9b78' (Size = 450), @p80=NULL (DbType = Int32), @p81=NULL (DbType = Int32), @p82='0' (Nullable = true), @p83='5', @p84='0' (Nullable = true), @p85='0' (Nullable = true), @p86=NULL (DbType = Int32), @p87='2022-11-09T14:55:22.8900877', @p88=NULL (DbType = DateTime2), @p89='cbb3a5d9-e9a9-450e-9026-aece053bee36' (Size = 450), @p90=NULL (DbType = Int32), @p91=NULL (DbType = Int32), @p92='0' (Nullable = true), @p93='5', @p94='0' (Nullable = true), @p95='0' (Nullable = true), @p96=NULL (DbType = Int32), @p97='2022-11-09T14:55:22.8900877', @p98=NULL (DbType = DateTime2), @p99='7a286685-3e64-485a-911c-90636e19fa85' (Size = 450), @p100=NULL (DbType = Int32), @p101=NULL (DbType = Int32), @p102='0' (Nullable = true), @p103='5', @p104='0' (Nullable = true), @p105='0' (Nullable = true), @p106=NULL (DbType = Int32), @p107='2022-11-09T14:55:22.8900877', @p108=NULL (DbType = DateTime2), @p109='3300efe5-139a-4164-94a7-72a432dada33' (Size = 450), @p110=NULL (DbType = Int32), @p111=NULL (DbType = Int32), @p112='0' (Nullable = true), @p113='5', @p114='0' (Nullable = true), @p115='0' (Nullable = true), @p116=NULL (DbType = Int32), @p117='2022-11-09T14:55:22.8900877', @p118=NULL (DbType = DateTime2), @p119='5f0b6cf8-0fe3-4236-af16-cdce6ba64228' (Size = 450), @p120=NULL (DbType = Int32), @p121=NULL (DbType = Int32), @p122='0' (Nullable = true), @p123='5', @p124='0' (Nullable = true), @p125='0' (Nullable = true), @p126=NULL (DbType = Int32), @p127='2022-11-09T14:55:22.8900877', @p128=NULL (DbType = DateTime2), @p129='8ff71738-4de1-442a-b6c3-c7d64a6792da' (Size = 450), @p130=NULL (DbType = Int32), @p131=NULL (DbType = Int32), @p132='0' (Nullable = true), @p133='5', @p134='0' (Nullable = true), @p135='0' (Nullable = true), @p136=NULL (DbType = Int32), @p137='2022-11-09T14:55:22.8900877', @p138=NULL (DbType = DateTime2), @p139='76b35648-2a76-42de-8aae-e780add568a0' (Size = 450), @p140=NULL (DbType = Int32), @p141=NULL (DbType = Int32), @p142='0' (Nullable = true), @p143='5', @p144='0' (Nullable = true), @p145='0' (Nullable = true), @p146=NULL (DbType = Int32), @p147='2022-11-09T14:55:22.8900877', @p148=NULL (DbType = DateTime2), @p149='8883df37-8c65-4a3f-b5f3-d488a2363ea4' (Size = 450), @p150=NULL (DbType = Int32), @p151=NULL (DbType = Int32), @p152='0' (Nullable = true), @p153='5', @p154='0' (Nullable = true), @p155='0' (Nullable = true), @p156=NULL (DbType = Int32), @p157='2022-11-09T14:55:22.8900877', @p158=NULL (DbType = DateTime2), @p159='315daed1-4855-4166-9ea3-5964907e8f16' (Size = 450), @p160=NULL (DbType = Int32), @p161=NULL (DbType = Int32), @p162='0' (Nullable = true), @p163='5', @p164='0' (Nullable = true), @p165='0' (Nullable = true), @p166=NULL (DbType = Int32), @p167='2022-11-09T14:55:22.8900877', @p168=NULL (DbType = DateTime2), @p169='00b18a32-b58e-417a-9cda-41f14c6a9a47' (Size = 450), @p170=NULL (DbType = Int32), @p171=NULL (DbType = Int32), @p172='0' (Nullable = true), @p173='5', @p174='0' (Nullable = true), @p175='0' (Nullable = true), @p176=NULL (DbType = Int32), @p177='2022-11-09T14:55:22.8900877', @p178=NULL (DbType = DateTime2), @p179='1057fe5d-5ed9-4e97-a6c3-a6ca73a32d7f' (Size = 450), @p180=NULL (DbType = Int32), @p181=NULL (DbType = Int32), @p182='0' (Nullable = true), @p183='5', @p184='0' (Nullable = true), @p185='0' (Nullable = true), @p186=NULL (DbType = Int32), @p187='2022-11-09T14:55:22.8900877', @p188=NULL (DbType = DateTime2), @p189='af71f453-c6b8-42f0-b0b4-6dce3b5847ec' (Size = 450), @p190=NULL (DbType = Int32), @p191=NULL (DbType = Int32), @p192='0' (Nullable = true), @p193='5', @p194='0' (Nullable = true), @p195='0' (Nullable = true), @p196=NULL (DbType = Int32), @p197='2022-11-09T14:55:22.8900877', @p198=NULL (DbType = DateTime2), @p199='1f72e993-2beb-4d8e-8386-f82b61c1a84e' (Size = 450), @p200=NULL (DbType = Int32), @p201=NULL (DbType = Int32), @p202='0' (Nullable = true), @p203='5', @p204='0' (Nullable = true), @p205='0' (Nullable = true), @p206=NULL (DbType = Int32), @p207='2022-11-09T14:55:22.8900877', @p208=NULL (DbType = DateTime2), @p209='9687efbc-2cb3-44d9-9819-720aac6361ef' (Size = 450), @p210=NULL (DbType = Int32), @p211=NULL (DbType = Int32), @p212='0' (Nullable = true), @p213='5', @p214='0' (Nullable = true), @p215='0' (Nullable = true), @p216=NULL (DbType = Int32), @p217='2022-11-09T14:55:22.8900877', @p218=NULL (DbType = DateTime2), @p219='6020039f-7349-405a-8968-add60fa8dd0f' (Size = 450), @p220=NULL (DbType = Int32), @p221=NULL (DbType = Int32), @p222='0' (Nullable = true), @p223='5', @p224='0' (Nullable = true), @p225='0' (Nullable = true), @p226=NULL (DbType = Int32), @p227='2022-11-09T14:55:22.8900877', @p228=NULL (DbType = DateTime2), @p229='57fbf1d3-b8d6-4ac2-b08f-876eac6a0dcb' (Size = 450), @p230=NULL (DbType = Int32), @p231=NULL (DbType = Int32), @p232='0' (Nullable = true), @p233='5', @p234='0' (Nullable = true), @p235='0' (Nullable = true), @p236=NULL (DbType = Int32), @p237='2022-11-09T14:55:22.8900877', @p238=NULL (DbType = DateTime2), @p239='f2bf55dc-4bba-437a-9dcd-f899a608e273' (Size = 450), @p240=NULL (DbType = Int32), @p241=NULL (DbType = Int32), @p242='0' (Nullable = true), @p243='5', @p244='0' (Nullable = true), @p245='0' (Nullable = true), @p246=NULL (DbType = Int32), @p247='2022-11-09T14:55:22.8900877', @p248=NULL (DbType = DateTime2), @p249='74570ede-c128-4a7d-ab93-287443480105' (Size = 450), @p250=NULL (DbType = Int32), @p251=NULL (DbType = Int32), @p252='0' (Nullable = true), @p253='5', @p254='0' (Nullable = true), @p255='0' (Nullable = true), @p256=NULL (DbType = Int32), @p257='2022-11-09T14:55:22.8900877', @p258=NULL (DbType = DateTime2), @p259='fc94704c-c3bb-43ad-aafc-560f4d0ee591' (Size = 450), @p260=NULL (DbType = Int32), @p261=NULL (DbType = Int32), @p262='0' (Nullable = true), @p263='5', @p264='0' (Nullable = true), @p265='0' (Nullable = true), @p266=NULL (DbType = Int32), @p267='2022-11-09T14:55:22.8900877', @p268=NULL (DbType = DateTime2), @p269='e81441c5-e084-41b9-8240-c666ca30b85f' (Size = 450), @p270=NULL (DbType = Int32), @p271=NULL (DbType = Int32), @p272='0' (Nullable = true), @p273='5', @p274='0' (Nullable = true), @p275='0' (Nullable = true), @p276=NULL (DbType = Int32), @p277='2022-11-09T14:55:22.8900877', @p278=NULL (DbType = DateTime2), @p279='969f492e-b8c4-4714-9f7c-f175cbd2b38a' (Size = 450), @p280=NULL (DbType = Int32), @p281=NULL (DbType = Int32), @p282='0' (Nullable = true), @p283='5', @p284='0' (Nullable = true), @p285='0' (Nullable = true), @p286=NULL (DbType = Int32), @p287='2022-11-09T14:55:22.8900877', @p288=NULL (DbType = DateTime2), @p289='f4ddf2da-ce69-418b-8e52-2c3a09191565' (Size = 450), @p290=NULL (DbType = Int32), @p291=NULL (DbType = Int32), @p292='0' (Nullable = true), @p293='5', @p294='0' (Nullable = true), @p295='0' (Nullable = true), @p296=NULL (DbType = Int32), @p297='2022-11-09T14:55:22.8900877', @p298=NULL (DbType = DateTime2), @p299='1bba624a-cc29-42ff-bcdc-9d2f1cb7cf07' (Size = 450), @p300=NULL (DbType = Int32), @p301=NULL (DbType = Int32), @p302='0' (Nullable = true), @p303='5', @p304='0' (Nullable = true), @p305='0' (Nullable = true), @p306=NULL (DbType = Int32), @p307='2022-11-09T14:55:22.8900877', @p308=NULL (DbType = DateTime2), @p309='8ebcaf53-f660-491a-ae3c-364c717f1359' (Size = 450), @p310=NULL (DbType = Int32), @p311=NULL (DbType = Int32), @p312='0' (Nullable = true), @p313='5', @p314='0' (Nullable = true), @p315='0' (Nullable = true), @p316=NULL (DbType = Int32), @p317='2022-11-09T14:55:22.8900877', @p318=NULL (DbType = DateTime2), @p319='e93cf5e7-a042-4ad6-a012-fb3dbb053f8e' (Size = 450), @p320=NULL (DbType = Int32), @p321=NULL (DbType = Int32), @p322='0' (Nullable = true), @p323='5', @p324='0' (Nullable = true), @p325='0' (Nullable = true), @p326=NULL (DbType = Int32), @p327='2022-11-09T14:55:22.8900877', @p328=NULL (DbType = DateTime2), @p329='0927304a-371e-4e6f-a963-04c1a0d165f5' (Size = 450), @p330=NULL (DbType = Int32), @p331=NULL (DbType = Int32), @p332='0' (Nullable = true), @p333='5', @p334='0' (Nullable = true), @p335='0' (Nullable = true), @p336=NULL (DbType = Int32), @p337='2022-11-09T14:55:22.8900877', @p338=NULL (DbType = DateTime2), @p339='da3a6162-359e-4b8e-91be-286293ebb2a0' (Size = 450), @p340=NULL (DbType = Int32), @p341=NULL (DbType = Int32), @p342='0' (Nullable = true), @p343='5', @p344='0' (Nullable = true), @p345='0' (Nullable = true), @p346=NULL (DbType = Int32), @p347='2022-11-09T14:55:22.8900877', @p348=NULL (DbType = DateTime2), @p349='628a5003-4e1f-4f45-8331-f0896432c83a' (Size = 450), @p350=NULL (DbType = Int32), @p351=NULL (DbType = Int32), @p352='0' (Nullable = true), @p353='5', @p354='0' (Nullable = true), @p355='0' (Nullable = true), @p356=NULL (DbType = Int32), @p357='2022-11-09T14:55:22.8900877', @p358=NULL (DbType = DateTime2), @p359='2d427c56-0d2d-44c8-a1e9-eeced1a4a757' (Size = 450), @p360=NULL (DbType = Int32), @p361=NULL (DbType = Int32), @p362='0' (Nullable = true), @p363='5', @p364='0' (Nullable = true), @p365='0' (Nullable = true), @p366=NULL (DbType = Int32), @p367='2022-11-09T14:55:22.8900877', @p368=NULL (DbType = DateTime2), @p369='c7a14338-42b4-4b1d-ab2a-b95562ac65a8' (Size = 450), @p370=NULL (DbType = Int32), @p371=NULL (DbType = Int32), @p372='0' (Nullable = true), @p373='5', @p374='0' (Nullable = true), @p375='0' (Nullable = true), @p376=NULL (DbType = Int32), @p377='2022-11-09T14:55:22.8900877', @p378=NULL (DbType = DateTime2), @p379='fef8e766-b586-4a1b-99e5-e33ef58284a5' (Size = 450), @p380=NULL (DbType = Int32), @p381=NULL (DbType = Int32), @p382='0' (Nullable = true), @p383='5', @p384='0' (Nullable = true), @p385='0' (Nullable = true), @p386=NULL (DbType = Int32), @p387='2022-11-09T14:55:22.8900877', @p388=NULL (DbType = DateTime2), @p389='da8d5041-81cb-49da-a208-749ef92434c5' (Size = 450), @p390=NULL (DbType = Int32), @p391=NULL (DbType = Int32), @p392='0' (Nullable = true), @p393='5', @p394='0' (Nullable = true), @p395='0' (Nullable = true), @p396=NULL (DbType = Int32), @p397='2022-11-09T14:55:22.8900877', @p398=NULL (DbType = DateTime2), @p399='2b6e0e3a-cb46-4d36-bd87-b283d710805c' (Size = 450), @p400=NULL (DbType = Int32), @p401=NULL (DbType = Int32), @p402='0' (Nullable = true), @p403='5', @p404='0' (Nullable = true), @p405='0' (Nullable = true), @p406=NULL (DbType = Int32), @p407='2022-11-09T14:55:22.8900877', @p408=NULL (DbType = DateTime2), @p409='7fbd5874-7132-44bc-9b5f-830971bc415f' (Size = 450), @p410=NULL (DbType = Int32), @p411=NULL (DbType = Int32), @p412='0' (Nullable = true), @p413='5', @p414='0' (Nullable = true), @p415='0' (Nullable = true), @p416=NULL (DbType = Int32), @p417='2022-11-09T14:55:22.8900877', @p418=NULL (DbType = DateTime2), @p419='dded04ee-7db6-4031-b7ae-cb7632863040' (Size = 450)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
MERGE [Notifications] USING (
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, 0),
(@p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, 1),
(@p20, @p21, @p22, @p23, @p24, @p25, @p26, @p27, @p28, @p29, 2),
(@p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39, 3),
(@p40, @p41, @p42, @p43, @p44, @p45, @p46, @p47, @p48, @p49, 4),
(@p50, @p51, @p52, @p53, @p54, @p55, @p56, @p57, @p58, @p59, 5),
(@p60, @p61, @p62, @p63, @p64, @p65, @p66, @p67, @p68, @p69, 6),
(@p70, @p71, @p72, @p73, @p74, @p75, @p76, @p77, @p78, @p79, 7),
(@p80, @p81, @p82, @p83, @p84, @p85, @p86, @p87, @p88, @p89, 8),
(@p90, @p91, @p92, @p93, @p94, @p95, @p96, @p97, @p98, @p99, 9),
(@p100, @p101, @p102, @p103, @p104, @p105, @p106, @p107, @p108, @p109, 10),
(@p110, @p111, @p112, @p113, @p114, @p115, @p116, @p117, @p118, @p119, 11),
(@p120, @p121, @p122, @p123, @p124, @p125, @p126, @p127, @p128, @p129, 12),
(@p130, @p131, @p132, @p133, @p134, @p135, @p136, @p137, @p138, @p139, 13),
(@p140, @p141, @p142, @p143, @p144, @p145, @p146, @p147, @p148, @p149, 14),
(@p150, @p151, @p152, @p153, @p154, @p155, @p156, @p157, @p158, @p159, 15),
(@p160, @p161, @p162, @p163, @p164, @p165, @p166, @p167, @p168, @p169, 16),
(@p170, @p171, @p172, @p173, @p174, @p175, @p176, @p177, @p178, @p179, 17),
(@p180, @p181, @p182, @p183, @p184, @p185, @p186, @p187, @p188, @p189, 18),
(@p190, @p191, @p192, @p193, @p194, @p195, @p196, @p197, @p198, @p199, 19),
(@p200, @p201, @p202, @p203, @p204, @p205, @p206, @p207, @p208, @p209, 20),
(@p210, @p211, @p212, @p213, @p214, @p215, @p216, @p217, @p218, @p219, 21),
(@p220, @p221, @p222, @p223, @p224, @p225, @p226, @p227, @p228, @p229, 22),
(@p230, @p231, @p232, @p233, @p234, @p235, @p236, @p237, @p238, @p239, 23),
(@p240, @p241, @p242, @p243, @p244, @p245, @p246, @p247, @p248, @p249, 24),
(@p250, @p251, @p252, @p253, @p254, @p255, @p256, @p257, @p258, @p259, 25),
(@p260, @p261, @p262, @p263, @p264, @p265, @p266, @p267, @p268, @p269, 26),
(@p270, @p271, @p272, @p273, @p274, @p275, @p276, @p277, @p278, @p279, 27),
(@p280, @p281, @p282, @p283, @p284, @p285, @p286, @p287, @p288, @p289, 28),
(@p290, @p291, @p292, @p293, @p294, @p295, @p296, @p297, @p298, @p299, 29),
(@p300, @p301, @p302, @p303, @p304, @p305, @p306, @p307, @p308, @p309, 30),
(@p310, @p311, @p312, @p313, @p314, @p315, @p316, @p317, @p318, @p319, 31),
(@p320, @p321, @p322, @p323, @p324, @p325, @p326, @p327, @p328, @p329, 32),
(@p330, @p331, @p332, @p333, @p334, @p335, @p336, @p337, @p338, @p339, 33),
(@p340, @p341, @p342, @p343, @p344, @p345, @p346, @p347, @p348, @p349, 34),
(@p350, @p351, @p352, @p353, @p354, @p355, @p356, @p357, @p358, @p359, 35),
(@p360, @p361, @p362, @p363, @p364, @p365, @p366, @p367, @p368, @p369, 36),
(@p370, @p371, @p372, @p373, @p374, @p375, @p376, @p377, @p378, @p379, 37),
(@p380, @p381, @p382, @p383, @p384, @p385, @p386, @p387, @p388, @p389, 38),
(@p390, @p391, @p392, @p393, @p394, @p395, @p396, @p397, @p398, @p399, 39),
(@p400, @p401, @p402, @p403, @p404, @p405, @p406, @p407, @p408, @p409, 40),
(@p410, @p411, @p412, @p413, @p414, @p415, @p416, @p417, @p418, @p419, 41)) AS i ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId], _Position) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId])
VALUES (i.[ContactId], i.[EmailMessageId], i.[InvestorsUnanswered], i.[Kind], i.[MessagesUnread], i.[OffersUnanswered], i.[SmsMessageId], i.[TimeCreatedUtc], i.[TimeDismissedUtc], i.[UserId])
OUTPUT INSERTED.[Id], i._Position;
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482531' to '82652' for entity with key '{Id: 82652}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482515' to '82668' for entity with key '{Id: 82668}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482530' to '82653' for entity with key '{Id: 82653}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482546' to '82637' for entity with key '{Id: 82637}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482518' to '82665' for entity with key '{Id: 82665}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482528' to '82655' for entity with key '{Id: 82655}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482508' to '82675' for entity with key '{Id: 82675}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482512' to '82671' for entity with key '{Id: 82671}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482532' to '82651' for entity with key '{Id: 82651}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482537' to '82646' for entity with key '{Id: 82646}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482545' to '82638' for entity with key '{Id: 82638}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482525' to '82658' for entity with key '{Id: 82658}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482536' to '82647' for entity with key '{Id: 82647}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482526' to '82657' for entity with key '{Id: 82657}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482513' to '82670' for entity with key '{Id: 82670}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482523' to '82660' for entity with key '{Id: 82660}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482534' to '82649' for entity with key '{Id: 82649}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482538' to '82645' for entity with key '{Id: 82645}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482507' to '82676' for entity with key '{Id: 82676}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482533' to '82650' for entity with key '{Id: 82650}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482543' to '82640' for entity with key '{Id: 82640}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482517' to '82666' for entity with key '{Id: 82666}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482535' to '82648' for entity with key '{Id: 82648}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482547' to '82636' for entity with key '{Id: 82636}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482527' to '82656' for entity with key '{Id: 82656}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482520' to '82663' for entity with key '{Id: 82663}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482540' to '82643' for entity with key '{Id: 82643}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482544' to '82639' for entity with key '{Id: 82639}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482529' to '82654' for entity with key '{Id: 82654}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482542' to '82641' for entity with key '{Id: 82641}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482511' to '82672' for entity with key '{Id: 82672}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482539' to '82644' for entity with key '{Id: 82644}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482514' to '82669' for entity with key '{Id: 82669}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482509' to '82674' for entity with key '{Id: 82674}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482506' to '82677' for entity with key '{Id: 82677}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482521' to '82662' for entity with key '{Id: 82662}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482541' to '82642' for entity with key '{Id: 82642}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482516' to '82667' for entity with key '{Id: 82667}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482524' to '82659' for entity with key '{Id: 82659}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482519' to '82664' for entity with key '{Id: 82664}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482522' to '82661' for entity with key '{Id: 82661}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '82677' to '82673' for entity with key '{Id: 82673}'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Closing data reader to 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: A data reader for 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' is being disposed after spending 144ms reading results.
Microsoft.EntityFrameworkCore.Update: Debug: Executing 8 update commands as a batch.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Creating DbCommand for 'ExecuteReader'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Created DbCommand for 'ExecuteReader' (2ms).
Microsoft.EntityFrameworkCore.Database.Command: Debug: Initialized DbCommand for 'ExecuteReader' (5ms).
Microsoft.EntityFrameworkCore.Database.Command: Debug: Executing DbCommand [Parameters=[@p0=NULL (DbType = Int32), @p1=NULL (DbType = Int32), @p2='0' (Nullable = true), @p3='5', @p4='0' (Nullable = true), @p5='0' (Nullable = true), @p6=NULL (DbType = Int32), @p7='2022-11-09T14:55:22.8900877', @p8=NULL (DbType = DateTime2), @p9='7c924b6c-651e-4531-8843-6dcbf6ae7875' (Size = 450), @p10=NULL (DbType = Int32), @p11=NULL (DbType = Int32), @p12='0' (Nullable = true), @p13='5', @p14='0' (Nullable = true), @p15='0' (Nullable = true), @p16=NULL (DbType = Int32), @p17='2022-11-09T14:55:22.8900877', @p18=NULL (DbType = DateTime2), @p19='de602419-829f-41dc-81b5-2b56ab05ae84' (Size = 450), @p20=NULL (DbType = Int32), @p21=NULL (DbType = Int32), @p22='0' (Nullable = true), @p23='5', @p24='0' (Nullable = true), @p25='0' (Nullable = true), @p26=NULL (DbType = Int32), @p27='2022-11-09T14:55:22.8900877', @p28=NULL (DbType = DateTime2), @p29='ada8d2a8-3d30-4332-9c6f-2efdf38adc37' (Size = 450), @p30=NULL (DbType = Int32), @p31=NULL (DbType = Int32), @p32='0' (Nullable = true), @p33='5', @p34='0' (Nullable = true), @p35='0' (Nullable = true), @p36=NULL (DbType = Int32), @p37='2022-11-09T14:55:22.8900877', @p38=NULL (DbType = DateTime2), @p39='a1e4ff1a-4649-4197-adcb-c4d694b955d8' (Size = 450), @p40=NULL (DbType = Int32), @p41=NULL (DbType = Int32), @p42='0' (Nullable = true), @p43='5', @p44='0' (Nullable = true), @p45='0' (Nullable = true), @p46=NULL (DbType = Int32), @p47='2022-11-09T14:55:22.8900877', @p48=NULL (DbType = DateTime2), @p49='bbeec8da-da0e-43bc-a724-ec023a27cbd5' (Size = 450), @p50=NULL (DbType = Int32), @p51=NULL (DbType = Int32), @p52='0' (Nullable = true), @p53='5', @p54='0' (Nullable = true), @p55='0' (Nullable = true), @p56=NULL (DbType = Int32), @p57='2022-11-09T14:55:22.8900877', @p58=NULL (DbType = DateTime2), @p59='50180c3f-b29a-4b2e-ae8e-a4ffe5498462' (Size = 450), @p60=NULL (DbType = Int32), @p61=NULL (DbType = Int32), @p62='0' (Nullable = true), @p63='5', @p64='0' (Nullable = true), @p65='0' (Nullable = true), @p66=NULL (DbType = Int32), @p67='2022-11-09T14:55:22.8900877', @p68=NULL (DbType = DateTime2), @p69='fc40707f-3680-41eb-86ca-0789f39ad73c' (Size = 450), @p70=NULL (DbType = Int32), @p71=NULL (DbType = Int32), @p72='0' (Nullable = true), @p73='5', @p74='0' (Nullable = true), @p75='0' (Nullable = true), @p76=NULL (DbType = Int32), @p77='2022-11-09T14:55:22.8900877', @p78=NULL (DbType = DateTime2), @p79='13e21b0c-83c4-4867-b311-192a7ac1f436' (Size = 450)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
MERGE [Notifications] USING (
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, 0),
(@p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, 1),
(@p20, @p21, @p22, @p23, @p24, @p25, @p26, @p27, @p28, @p29, 2),
(@p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39, 3),
(@p40, @p41, @p42, @p43, @p44, @p45, @p46, @p47, @p48, @p49, 4),
(@p50, @p51, @p52, @p53, @p54, @p55, @p56, @p57, @p58, @p59, 5),
(@p60, @p61, @p62, @p63, @p64, @p65, @p66, @p67, @p68, @p69, 6),
(@p70, @p71, @p72, @p73, @p74, @p75, @p76, @p77, @p78, @p79, 7)) AS i ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId], _Position) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId])
VALUES (i.[ContactId], i.[EmailMessageId], i.[InvestorsUnanswered], i.[Kind], i.[MessagesUnread], i.[OffersUnanswered], i.[SmsMessageId], i.[TimeCreatedUtc], i.[TimeDismissedUtc], i.[UserId])
OUTPUT INSERTED.[Id], i._Position;
Microsoft.EntityFrameworkCore.Database.Command: Information: Executed DbCommand (6ms) [Parameters=[@p0=NULL (DbType = Int32), @p1=NULL (DbType = Int32), @p2='0' (Nullable = true), @p3='5', @p4='0' (Nullable = true), @p5='0' (Nullable = true), @p6=NULL (DbType = Int32), @p7='2022-11-09T14:55:22.8900877', @p8=NULL (DbType = DateTime2), @p9='7c924b6c-651e-4531-8843-6dcbf6ae7875' (Size = 450), @p10=NULL (DbType = Int32), @p11=NULL (DbType = Int32), @p12='0' (Nullable = true), @p13='5', @p14='0' (Nullable = true), @p15='0' (Nullable = true), @p16=NULL (DbType = Int32), @p17='2022-11-09T14:55:22.8900877', @p18=NULL (DbType = DateTime2), @p19='de602419-829f-41dc-81b5-2b56ab05ae84' (Size = 450), @p20=NULL (DbType = Int32), @p21=NULL (DbType = Int32), @p22='0' (Nullable = true), @p23='5', @p24='0' (Nullable = true), @p25='0' (Nullable = true), @p26=NULL (DbType = Int32), @p27='2022-11-09T14:55:22.8900877', @p28=NULL (DbType = DateTime2), @p29='ada8d2a8-3d30-4332-9c6f-2efdf38adc37' (Size = 450), @p30=NULL (DbType = Int32), @p31=NULL (DbType = Int32), @p32='0' (Nullable = true), @p33='5', @p34='0' (Nullable = true), @p35='0' (Nullable = true), @p36=NULL (DbType = Int32), @p37='2022-11-09T14:55:22.8900877', @p38=NULL (DbType = DateTime2), @p39='a1e4ff1a-4649-4197-adcb-c4d694b955d8' (Size = 450), @p40=NULL (DbType = Int32), @p41=NULL (DbType = Int32), @p42='0' (Nullable = true), @p43='5', @p44='0' (Nullable = true), @p45='0' (Nullable = true), @p46=NULL (DbType = Int32), @p47='2022-11-09T14:55:22.8900877', @p48=NULL (DbType = DateTime2), @p49='bbeec8da-da0e-43bc-a724-ec023a27cbd5' (Size = 450), @p50=NULL (DbType = Int32), @p51=NULL (DbType = Int32), @p52='0' (Nullable = true), @p53='5', @p54='0' (Nullable = true), @p55='0' (Nullable = true), @p56=NULL (DbType = Int32), @p57='2022-11-09T14:55:22.8900877', @p58=NULL (DbType = DateTime2), @p59='50180c3f-b29a-4b2e-ae8e-a4ffe5498462' (Size = 450), @p60=NULL (DbType = Int32), @p61=NULL (DbType = Int32), @p62='0' (Nullable = true), @p63='5', @p64='0' (Nullable = true), @p65='0' (Nullable = true), @p66=NULL (DbType = Int32), @p67='2022-11-09T14:55:22.8900877', @p68=NULL (DbType = DateTime2), @p69='fc40707f-3680-41eb-86ca-0789f39ad73c' (Size = 450), @p70=NULL (DbType = Int32), @p71=NULL (DbType = Int32), @p72='0' (Nullable = true), @p73='5', @p74='0' (Nullable = true), @p75='0' (Nullable = true), @p76=NULL (DbType = Int32), @p77='2022-11-09T14:55:22.8900877', @p78=NULL (DbType = DateTime2), @p79='13e21b0c-83c4-4867-b311-192a7ac1f436' (Size = 450)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
MERGE [Notifications] USING (
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, 0),
(@p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, 1),
(@p20, @p21, @p22, @p23, @p24, @p25, @p26, @p27, @p28, @p29, 2),
(@p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39, 3),
(@p40, @p41, @p42, @p43, @p44, @p45, @p46, @p47, @p48, @p49, 4),
(@p50, @p51, @p52, @p53, @p54, @p55, @p56, @p57, @p58, @p59, 5),
(@p60, @p61, @p62, @p63, @p64, @p65, @p66, @p67, @p68, @p69, 6),
(@p70, @p71, @p72, @p73, @p74, @p75, @p76, @p77, @p78, @p79, 7)) AS i ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId], _Position) ON 1=0
WHEN NOT MATCHED THEN
INSERT ([ContactId], [EmailMessageId], [InvestorsUnanswered], [Kind], [MessagesUnread], [OffersUnanswered], [SmsMessageId], [TimeCreatedUtc], [TimeDismissedUtc], [UserId])
VALUES (i.[ContactId], i.[EmailMessageId], i.[InvestorsUnanswered], i.[Kind], i.[MessagesUnread], i.[OffersUnanswered], i.[SmsMessageId], i.[TimeCreatedUtc], i.[TimeDismissedUtc], i.[UserId])
OUTPUT INSERTED.[Id], i._Position;
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482505' to '82678' for entity with key '{Id: 82678}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482504' to '82679' for entity with key '{Id: 82679}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482503' to '82680' for entity with key '{Id: 82680}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482502' to '82681' for entity with key '{Id: 82681}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482501' to '82682' for entity with key '{Id: 82682}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482500' to '82683' for entity with key '{Id: 82683}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482499' to '82684' for entity with key '{Id: 82684}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482498' to '82685' for entity with key '{Id: 82685}'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: Closing data reader to 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Command: Debug: A data reader for 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' is being disposed after spending 23ms reading results.
Microsoft.EntityFrameworkCore.Database.Transaction: Debug: Committing transaction.
Microsoft.EntityFrameworkCore.Database.Transaction: Debug: Committed transaction.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Closing connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb'.
Microsoft.EntityFrameworkCore.Database.Connection: Debug: Closed connection to database 'WebAppLocalDb' on server '(localdb)\mssqllocaldb' (2ms).
Microsoft.EntityFrameworkCore.Database.Transaction: Debug: Disposing transaction.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82636}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82637}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82638}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82639}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82640}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82641}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82642}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82643}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82644}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82645}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82646}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82647}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82648}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82649}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82650}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82651}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82652}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82653}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82654}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82655}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82656}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82657}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82658}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82659}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82660}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82661}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82662}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82663}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82664}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82665}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82666}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82667}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82668}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82669}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82670}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82671}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The 'DailyDigest' entity with key '{Id: 82672}' tracked by 'ApplicationDbContext' changed state from 'Added' to 'Unchanged'.
Microsoft.EntityFrameworkCore.Update: Error: An exception occurred in the database while saving changes for context type 'WebApp.Data.ApplicationDbContext'.
System.InvalidOperationException: The property 'DailyDigest.Id' has a temporary value while attempting to change the entity's state to 'Unchanged'. Either set a permanent value explicitly, or ensure that the database is configured to generate values for this property.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.AcceptChanges()
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.AcceptAllChanges(IReadOnlyList`1 changedEntries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)

System.InvalidOperationException: The property 'DailyDigest.Id' has a temporary value while attempting to change the entity's state to 'Unchanged'. Either set a permanent value explicitly, or ensure that the database is configured to generate values for this property.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.AcceptChanges()
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.AcceptAllChanges(IReadOnlyList`1 changedEntries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)

@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 9, 2022

@ajcvickers Spent the day trying to get the repro project as similar to the real project as possible, adding generic host, connection pooling and enable multiple active result sets in connection string.

It still only reproduces in the real project but I have at least managed to get a debug log output which is identical to the real project log output, down to a few lines which may or may not have something to do with this bug. See the diff below, in real project when it fails a db reader is closed during detect changes phase.

Related or red herring? You decide.

image

edit: full diff here

@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 10, 2022

@ajcvickers @roji I think I managed to find something interesting today.

I experimented with maxCount (the .Take(maxCount) in the query) and it seems that I get the exception exactly on 32 items or more. All maxCount less than 32 works perfectly.

Then I tried reproducing with 32 items after adding the following workaround to the table configuration; builder.ToTable(tb => tb.HasTrigger("workaround"));

This works! 🤯

But the SQL query will be a bit different;

Without HasTrigger

OUTPUT INSERTED.[Id], i._Position;

With HasTrigger

OUTPUT INSERTED.[Id], i._Position
INTO @inserted0;

SELECT [i].[Id] FROM @inserted0 i
ORDER BY [i].[_Position];

Could this difference (missing sort) be the cause of this exception?

I hope you could have a look at this because at this moment I feel not safe about pushing EF7/NET7 to production without resolving this issue.

@joakimriedel joakimriedel changed the title Potential breaking change with identity column in EF Core 7 when saving entity generated from projection Issue with identity column in EF Core 7 when saving >31 entities generated from projection Nov 10, 2022
@roji
Copy link
Member

roji commented Nov 10, 2022

@joakimriedel the difference in SQL between the trigger and non-trigger cases - including the missing sort - are very much by-design, and are a performance optimization introduced in EF Core 7.0 (see this blog post for more information).

However, I don't doubt that there's a bug here; are you now able to submit a reprocible code sample, similar to what @ajcvickers attempted above?

@joakimriedel
Copy link
Contributor Author

@roji I've now spent ~16 hours trying to reproduce this outside of the real project. I've imported almost every aspect that I can think of that might affect the results from the real project into the repro project unsuccessfully. The only thing missing now is the real data, which would be the next step to import into repro project.

As I wrote above, the debug output from repro and real are the same, but it only fails in real project. In real project it is 100% reproducible. 31 items => no exception, 32 items => exception. 32 items w/ HasTrigger => no exception. 32 items where Id is set explicitly to default int => no exception. 32 items in version 6.0.10 => no exception.

As the bug is hard to reproduce in repro project I'm starting to think there is some kind of memory corruption, caching or timing issue that only occurs when full project is loaded and the entity graph is more saturated with data.

@roji
Copy link
Member

roji commented Nov 10, 2022

@joakimriedel any memory corruption here is very unlikely... Using actual (or similar) data in your repro is definitely a good step forward, otherwise it's good practice to start from your real project and progressively strip it down until you get a minimal repro.

In any case, I did do various work in this area for 7.0, so it makes sense for there to be a bug here.

@ajcvickers
Copy link
Member

From the logs, this looks suspicious:

...
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482412' to '82473' for entity with key '{Id: 82473}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482404' to '82481' for entity with key '{Id: 82481}'.
Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '82485' to '82460' for entity with key '{Id: 82460}'.

It looks like the foreign key Notification.Id property of many entities are getting generated key values propagated from the principal after they were generated by the database. These all replace temporary values except the last one, which is replacing a non-temp value.

Two theories:

  • The wrong entity is being updated for the last case, leaving the entity which should have been updated with a temporary value.
  • There is some circular dependency which is causing the same entity to be updated multiple times, and something is going wrong.

@joakimriedel Can you post the code for the Notification entity and its relationships?

@joakimriedel
Copy link
Contributor Author

@ajcvickers as you see earlier in the log, 82485 has already been set from temporary to database value.

Microsoft.EntityFrameworkCore.ChangeTracking: Debug: The foreign key property 'Notification.Id' was detected as changed from '-2147482400' to '82485' for entity with key '{Id: 82485}'.

I'm currently working on minimizing the real project down until it doesn't reproduce anymore as suggested by @roji will keep you posted soon. Notification is the abstract base class for DailyDigest.

@joakimriedel
Copy link
Contributor Author

@ajcvickers @roji just a quick update, it is definitely related to the specific data and how it is loaded.

I have managed to minimize the entire code in the real project (with real data) down to only the following lines and it still reproduces:

var digests = await _context.Users
    .OrderBy(u => u.TimeCreatedUtc)
    .Take(32)
    .Select(source => new DailyDigest
    {
        User = source,
    })
    .ToListAsync();

foreach (var digest in digests)
{
    _context.DailyDigests.Add(digest);
}
await _context.SaveChangesAsync();

Now for the fun part. The following two modifications to the code will prevent the exception:

  1. remove OrderBy
var digests = await _context.Users
    .Take(32)
    .Select(source => new DailyDigest
    {
        User = source,
    })
    .ToListAsync();

foreach (var digest in digests)
{
    _context.DailyDigests.Add(digest);
}
await _context.SaveChangesAsync();
  1. reduce to 31 items
var digests = await _context.Users
    .OrderBy(u => u.TimeCreatedUtc)
    .Take(31)
    .Select(source => new DailyDigest
    {
        User = source,
    })
    .ToListAsync();

foreach (var digest in digests)
{
    _context.DailyDigests.Add(digest);
}
await _context.SaveChangesAsync();

What kind of sorcery is this?? 🤔

@roji
Copy link
Member

roji commented Nov 10, 2022

@joakimriedel we're going to need the data here as well, as well as preferably a fully runnable console program (see @ajcvickers's repro above), in order to see the error happening on our side; once that's done, we can investigate and get to the root cause.

If the data is private, you can also send the stuff to my email (on my github profile), or invite me to a private github repo with the code and data.

@joakimriedel
Copy link
Contributor Author

@roji The User object above is quite big (28 columns) so my plan right now is to try bringing the data to a minimal db that I can provide for you (fingers crossed it still reproduces...) I'll keep you posted.

@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 10, 2022

@ajcvickers @roji 🎉 I finally managed to create a repro: https://github.com/joakimriedel/efcore-issue-29502/tree/repro

Run the database.sql script first to setup two tables, DailyDigests (empty) and AspNetUsers (with data).

Then run the solution. It will throw exception on SaveChangesAsync call.

Edit: Just found out that in this minimal repro, it throws exception on exactly 23 items, 22 and less works fine. Could there be anything in the seed data that makes it crash at row 23 ordered by time? 🤔
Edit 2: I have a theory. At exactly row 23, a big chunk of users has same year, month, day, hour, minute and second but differ only on milliseconds. Could this mess with the ordering returned from the SQL server? 🤯

@joakimriedel joakimriedel changed the title Issue with identity column in EF Core 7 when saving >31 entities generated from projection Issue with identity column in EF Core 7 when saving multiple entities generated from projection Nov 10, 2022
@joakimriedel
Copy link
Contributor Author

joakimriedel commented Nov 11, 2022

@ajcvickers @roji reduced repro complexity a bit in recent push, to make it as minimal as possible.

Some findings;

CREATE TABLE [dbo].[Users](
	[Id] [nvarchar](450) NOT NULL,
	[AccessFailedCount] [int] NOT NULL,
	[ConcurrencyStamp] [nvarchar](max) NULL,
	[Email] [nvarchar](256) NULL,
	[EmailConfirmed] [bit] NOT NULL,
	[LockoutEnabled] [bit] NOT NULL,
	[LockoutEnd] [datetimeoffset](7) NULL,
	[NormalizedEmail] [nvarchar](256) NULL,
	[NormalizedUserName] [nvarchar](256) NULL,
	[PasswordHash] [nvarchar](max) NULL,
	[PhoneNumber] [nvarchar](max) NULL,
	[PhoneNumberConfirmed] [bit] NOT NULL,
	[SecurityStamp] [nvarchar](max) NULL,
	[TwoFactorEnabled] [bit] NOT NULL,
	[UserName] [nvarchar](256) NULL,
	[TimeCreatedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

The columns from IdentityUser matters somehow, guessing it affects the order of items inserted later in the script. If I change the table columns to only

CREATE TABLE [dbo].[Users](
	[Id] [nvarchar](450) NOT NULL,
	[TimeCreatedUtc] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] 
GO

and then insert the data, it will not reproduce anymore.

But! If I run the script, and THEN delete the IdentityUser columns from database, it still reproduces. I guess the order of the rows does not change internally in SQL server when columns are deleted like that. And if I script the database without the IdentityUser columns and then create from that script - it doesn't reproduce anymore.

So, this bug must have something to do with the physical order of the columns within SQL Server. It's by far one of the deepest rabbit holes I've been into with Entity Framework Core so far... 🐰

Do you have any ideas on what we are looking at here?

@roji
Copy link
Member

roji commented Nov 11, 2022

Thanks for the dedicated work on this and for the repro - much appreciated. I'll dive into this in the coming days to get to the root cause, will post back here when I figure out what's going on.

roji added a commit to roji/efcore that referenced this issue Nov 16, 2022
@ewbi
Copy link

ewbi commented Nov 16, 2022

@roji, ahh, I missed that stored procedure condition in AddCommand, thanks.

Is a HasResultRow flag really equivalent to !NoResults? I don't see HasResultRow ever being set anywhere, and only used as a conditional check in AffectedCountModificationCommandBatch.Consume[Async].

@roji roji reopened this Nov 16, 2022
@roji
Copy link
Member

roji commented Nov 16, 2022

@ewbi HasResultRow is a bit that's also included in LastInResultSet/NotLastInResultSet (see source), so when you set the latter you get the former too. I know it's a bit complex, but hopefully not too much.

roji added a commit to roji/efcore that referenced this issue Nov 16, 2022
@roji roji changed the title Issue with identity column in EF Core 7 when saving multiple entities generated from projection Exception when inserting multiple rows into the same table on SQL Server Nov 16, 2022
@ewbi
Copy link

ewbi commented Nov 16, 2022

@roji, oh dang, I hadn't even considered the enum's values or noticed that they might overlap - that really is a spicy enum! :)

Thanks for the second look and hard work. I'll stop bugging you guys and let you get on with the v7 patching. I'm looking forward to turning that trigger workaround off and seeing what this new logic will do for our insert performance. Cheers.

@randalltomes
Copy link

I am using EF Core 7.0.1 and I can confirm inserting 30 records is the maximum I can bulk save. When I bump it to 31, I get the error:
System.Exception: The property 'Foo.Id' has a temporary value while attempting to change the entity's state to 'Unchanged'. Either set a permanent value explicitly, or ensure that the database is configured to generate values for this property.

counter++;
db.Foos.Add(newFooEntity);
if (counter % 30 == 0)
{
await db.SaveChangesAsync();
}

@roji
Copy link
Member

roji commented Jan 3, 2023

@randalltomes please give the latest daily build a try - a fix has already been merged there. That would allow us to confirm that there isn't an additional bug we're not aware of.

@randalltomes
Copy link

@roji I am on .Net 6. Followed the instructions on the daily build link but could not get the latest daily to show up in my Nuget Packages manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-save-changes area-sqlserver closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants