Is this working?
See original GitHub issueI have install this nuget packet in my sample project. But this don’t create any historie data in my database. Here my implementation:
DbContext:
public class BlogDataDbContext: DbContext
{
public BlogDataDbContext(DbContextOptions<BlogDataDbContext> options): base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.EnableAutoHistory(null);
}
public DbSet<Blog> Blogs { get; set; }
}
Somemethod of saving:
public class EditModel : PageModel
{
private readonly BlogDataDbContext _context;
public EditModel(BlogDataDbContext context)
{
_context = context;
_context.EnsureAutoHistory();
}
[BindProperty]
public Data.BlogData.Blog Blog { get; set; }
public async Task<IActionResult> OnGetAsync(Guid? id)
{
if (id == null)
{
return NotFound();
}
Blog = await _context.Blogs.SingleOrDefaultAsync(m => m.BlogId == id);
if (Blog == null)
{
return NotFound();
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Attach(Blog).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BlogExists(Blog.BlogId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToPage("./Index");
}
private bool BlogExists(Guid id)
{
return _context.Blogs.Any(e => e.BlogId == id);
}
}
After the change of an element no new entry in the AutoHistorie table. This is strange…
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Is This Working?
There's no agreement about how teachers should discipline students. And there's evidence that some of the most popular punishments may harm ...
Read more >Is This Working? - Hosted by Anna Codrea-Rado and ...
Listen to episodes and learn more about Is This Working?. A podcast about the messy parts of work, co-hosted by Anna Codrea-Rado and...
Read more >Is This Working?
A podcast about the messy parts of work, co-hosted by Anna Codrea-Rado and Tiffany Philippou. ... Hosted on Acast. See acast.com/privacy for more...
Read more >This American Life: “Is This Working?”
This podcast raises issues of racial inequality in school discipline and how teachers ought to discipline students. Topics/Themes: School discipline.
Read more >Is This Working?: The Businesslady's Guide to Getting ...
Is This Working?: The Businesslady's Guide to Getting What You Want from Your Career: Guerra, Courtney C.W.: 9781440598494: Amazon.com: Books.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, maybe the README SHOULD be updated.
Oh, I’m sorry,
_context.SaveChangesAsync(true);
is my UnitOfWork feature, If you only use this nuget package, the correct usage is invoke_context.EnsureAutoHistory();
beforeawait _context.SaveChangesAsync();
Tips: Your issue is your code invoke the
_context.EnsureAutoHistory();
inEditModel
constructor, but nothing changed in there. The correct is in yourOnPostAsync()
like following: