Merge pull request #4705 from maurocavallin/dev
Hard deletion of page more robust use of entity framework contexts
This commit is contained in:
commit
1047058676
@ -91,6 +91,7 @@ namespace Oqtane.Repository
|
||||
public void DeletePage(int pageId)
|
||||
{
|
||||
using var db = _dbContextFactory.CreateDbContext();
|
||||
{
|
||||
var page = db.Page.Find(pageId);
|
||||
_permissions.DeletePermissions(page.SiteId, EntityNames.Page, pageId);
|
||||
_settings.DeleteSettings(EntityNames.Page, pageId);
|
||||
@ -100,9 +101,19 @@ namespace Oqtane.Repository
|
||||
{
|
||||
_pageModules.DeletePageModule(pageModule.PageModuleId);
|
||||
}
|
||||
// must occur after page modules are deleted because of cascading delete relationship
|
||||
db.Page.Remove(page);
|
||||
db.SaveChanges();
|
||||
|
||||
// At this point the page item is unaware of changes happened in other
|
||||
// contexts (i.e.: the contex opened and closed in each DeletePageModule).
|
||||
// Workin on page item may result in unxpected behaviour:
|
||||
// better close and reopen context to work on a fresh page item.
|
||||
}
|
||||
|
||||
using var dbContext = _dbContextFactory.CreateDbContext();
|
||||
{
|
||||
var page = dbContext.Page.Find(pageId);
|
||||
dbContext.Page.Remove(page);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user