-1

The only question that I found most similar to my question is here, But It didn't answer my question. I have this model:

public class Profile
{
    public int Id { get; set; }
    public string Name { get; set; }
    public bool IsActive { get; set; }  
    public bool IsDeleted {get; set; }
    public virtual ICollection<Program> AllowedPrograms { get; set; }
    public virtual ICollection<Program> DisAllowedPrograms { get; set; }
}

and this :

public class Program
{
    public int Id { get; set; }
    public string DisplayName { get; set; }     
    public bool IsActive { get; set; }
    public bool IsDeleted {get; set; }
    public virtual ICollection<Profile> AllowedProfiles { get; set; }
    public virtual ICollection<Profile> DisAllowedProfiles { get; set; }

}

If I implement soft delete by help of IsDeleted field, What happens to entries in ProfileProgram table ? Are they deleted too implicitly? (There is two many-to-many relationships in this model I guess ). If I use entity framework filters which is located in here.

Or should I create the intermediate table by myself and add IsDeleted field to that? Also this approach seems to change my code a lot which I am really looking for alternate method.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Rathma
  • 1,196
  • 2
  • 33
  • 65
  • There's no "deleted too implicitly". There's no "soft delete". Delete means delete. "Soft delete" is the unfortunate name used for updating a field on a row so it won't be retrieved from a query. Where's your query? – Panagiotis Kanavos Jun 08 '18 at 13:10
  • As for the downvotes, because it's not a good question. You don't show what you did to implement "soft delete" at all. People can't help you find problems in your code if you don't post that code – Panagiotis Kanavos Jun 08 '18 at 13:11
  • Finally, "soft delete" doesn't exist in the real world or in businesses. Companies don't delete. They change the status of their records and keep track of the changes. If a program is discontinued its status is changed to `Discontinued` with an end date. When it's time to delete, eg due to GDPR rules, they *delete* the records in the physical sense – Panagiotis Kanavos Jun 08 '18 at 13:13
  • @PanagiotisKanavos soft delete is soft delete ! I guess every one in banking or security applications know what I mean, And I have showed that it is implemented by `IsDelete` field and linked one relevant question which gives enough context. And exactly my question is How should ** I implement soft delete in many-to-many relationships !** – Rathma Jun 08 '18 at 13:15
  • Some applications, nothing is deleted! Banking or security ones, so why my client has asked me to do so? – Rathma Jun 08 '18 at 13:18
  • So will you please comment on every question in here and inform them that there is no soft delete ! https://stackoverflow.com/questions/tagged/soft-delete ?? – Rathma Jun 08 '18 at 13:21
  • No, banks don't use "soft delete". They don't delete accounts and transactions, that's illegal - as in money-laundering, go 10 years to prison illegal. They update the status of their records. That's what you ask here too. You want to modify the value of an `IsDelete` attribute. If you want related entities to change their status as well, *you* will have to modify them in code. – Panagiotis Kanavos Jun 08 '18 at 13:28
  • As for the tagged questions, look at the downvotes and the actual *contents*. All of them are *queries* based on status fields. You can simplify things a *LOT* if you don't try to hard-code those queries. Instead of trying to find records with the `IsDeleted` field, map to a *view* that only returns active records. Use triggers or stored procedures to update the status and cascade changes *only if * it's necessary. Most of the time it isn't. – Panagiotis Kanavos Jun 08 '18 at 13:30
  • Many applications use history table to track the history of business entities, especially in the banking and finance sector. You can use temporal tables too to make tracking of changes easier. – Panagiotis Kanavos Jun 08 '18 at 13:33
  • Finally, check Oren Eini's articles on why one should [Avoid soft deletes](https://ayende.com/blog/4157/avoid-soft-deletes) . He's one of the people that made NHibernate one of the most popular ORMs in the .NET world. – Panagiotis Kanavos Jun 08 '18 at 13:35
  • 1
    You want to update an additional field in the junction table (`IsDeleted`). So the junction table should inevitably become a visible entity in your model. – Gert Arnold Jun 08 '18 at 20:39

1 Answers1

1

Yes the ProfileProgram table isn't automatically deleted. Yes you should create the IsDeleted table (not field).

user234461
  • 1,133
  • 12
  • 29