Disable Cascading delete not working

Hello,

If I disable Cascading delete in Code generation settings Cascading delete still is used:

image

I cannot see any difference if it is disabled or enabled in generated code:

public async Task<PDBIntern.Models.PDB.Bezirk> DeleteBezirk(int bezirkid)
        {
            var itemToDelete = Context.Bezirks
                              .Where(i => i.Bezirk_ID == bezirkid)
                              .FirstOrDefault();

            if (itemToDelete == null)
            {
               throw new Exception("Item no longer available");
            }

            OnBezirkDeleted(itemToDelete);


            Context.Bezirks.Remove(itemToDelete);

            try
            {
                Context.SaveChanges();
            }
            catch
            {
                Context.Entry(itemToDelete).State = EntityState.Unchanged;
                throw;
            }

            OnAfterBezirkDeleted(itemToDelete);

            return itemToDelete;
        }

robert

I think this is done in your DbContext.

Check your

protected override void OnModelCreating(ModelBuilder builder)
{
...
}

In the definition of you entities could be something like this for disabled cascading:
.OnDelete(DeleteBehavior.Restrict)

No, there is no difference if it is enabled/disabled and no OnDelete(DeleteBehavior.Restrict)

maybe a Bug in Balzor Studio?

robert

I'm seeing the same thing as far as scaffolding with or without the cascade delete flag set does not change the code at all.

When cascade delete is enabled the Delete method in the service in Blazor server app and the ODataController in the WebAssembly app will have Include() for related entities:

I double checked our template and I've noticed that there are cases where the code will not be generated - the problem is fixed immediately and the fix will be part of our next update today/tomorrow.

1 Like

Just FYI, confirmed it now works as expected in 1.8.0

Could you please add to the list of enhancements to save the prior setting?

I don't want cascade delete and am re-scaffolding often, every time I need to uncheck it rather that it remembering the setting from the last run.

Same for the CRUD configuration, would be great if remembered those values from the prior run.