We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have updated my project to .Net core 3.0.
Following the article, I did the below in my MVC web application project
class CustomAutoHistory : AutoHistory { public int UserId { get; set; } }
Then register it in the db context like follows: modelBuilder.EnableAutoHistory<CustomAutoHistory>(o => { });
modelBuilder.EnableAutoHistory<CustomAutoHistory>(o => { });
Then in my MVC controller code I did below
if (ModelState.IsValid) { try { _context.EnsureAutoHistory(() => new CustomAutoHistory() { UserId = Convert.ToInt16( User.FindFirstValue(ClaimTypes.NameIdentifier)) }); _context.Update(cust); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(cust.Id)) { return NotFound(); } else { throw; } } }
CustomAutoHistory table script
CREATE TABLE [dbo].[|CustomAutoHistory]( [Id] [int] IDENTITY(1,1) NOT NULL, [RowId] nvarchar NOT NULL, [TableName] nvarchar NOT NULL, [Changed] nvarchar NULL, [Kind] [int] NOT NULL, [Created] datetime2 NOT NULL, [UserId] [int] NULL, CONSTRAINT [PK_CustomAutoHistory] 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
The customer records gets updated but there is no record in the Custom History table. Can you please check the custom AutoHistory?
The text was updated successfully, but these errors were encountered:
Change the order of operations like so:
if (ModelState.IsValid) { try { _context.Update(cust); _context.EnsureAutoHistory(() => new CustomAutoHistory() { UserId = Convert.ToInt16(User.FindFirstValue(ClaimTypes.NameIdentifier)) }); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(cust.Id)) { return NotFound(); } else { throw; } } }
and try again
Sorry, something went wrong.
No branches or pull requests
I have updated my project to .Net core 3.0.
Following the article, I did the below in my MVC web application project
Then register it in the db context like follows:
modelBuilder.EnableAutoHistory<CustomAutoHistory>(o => { });
Then in my MVC controller code I did below
CustomAutoHistory table script
CREATE TABLE [dbo].[|CustomAutoHistory](
[Id] [int] IDENTITY(1,1) NOT NULL,
[RowId] nvarchar NOT NULL,
[TableName] nvarchar NOT NULL,
[Changed] nvarchar NULL,
[Kind] [int] NOT NULL,
[Created] datetime2 NOT NULL,
[UserId] [int] NULL,
CONSTRAINT [PK_CustomAutoHistory] 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
The customer records gets updated but there is no record in the Custom History table. Can you please check the custom AutoHistory?
The text was updated successfully, but these errors were encountered: