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

SoftDelete strange situation #2631

Closed
maliming opened this issue Oct 24, 2017 · 3 comments
Closed

SoftDelete strange situation #2631

maliming opened this issue Oct 24, 2017 · 3 comments

Comments

@maliming
Copy link
Member

Abp 2.3.0.0
EF 6.1.3

Two entities are inherited from ISoftDelete interfaces, one-to-many relationship.

var people= await _peopleRepository.GetAll().FirstOrDefaultAsync(x => x.Id == input.Id);
people.Files.Add(input.file.MapTo<Files>());

 _peopleRepository.Update(people);
 _peopleRepository.Delete(people);

We want to add an attachment and then soft delete the entity.

But the result is: the entity is soft deleted while the attachment is not successfully added, if the entity has previously attached the attachment will be soft deleted.

@hikalkan why is it like this?

@ryancyq
Copy link
Contributor

ryancyq commented Oct 24, 2017

Hi @maliming , it seems to be correct base on EF Code-First convention, see Cascade Delete

@maliming
Copy link
Member Author

@ryancyq You are right! Now i do like that:

people.IsDeleted = true;
people.DeletionTime = DateTime.Now;
people.DeleterUserId = AbpSession.GetUserId();

@hikalkan
Copy link
Member

When you delete an entity, ABP reloads it from database (this is the safest way to reset an entity's state), sets IsDeleted = true (and audit properties) and saves again.

It's not expected to change a property of an entity before delete it. Soft delete should be thought as a real delete.

In brief, it's by design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants