Have you ever implemented soft deletes in a production app? I've only had to do it a few times, but I really like the pattern and REALLY like the ability to have an "undo" built into the app.
@wayne_taylor8 ай бұрын
I have once in my own MVC app, I did a bool flag . The method used in the current work DB is a number which represents it's deleted 🙂
@BaldBeardedBuilder8 ай бұрын
@@wayne_taylor How is the number used? Like a bool? So 1 = true? Or is it some kind of state. Like 2 = something, 3 = deleted?
@taconaut82767 ай бұрын
I also had a few projects with soft delete. In the current one, we use temporal tables to track changes.
@BaldBeardedBuilder7 ай бұрын
@taconaut8276 that makes sense. I've got a video in the works now that discusses using interceptors for audit tracking you might be interested in.
@taconaut82767 ай бұрын
Sweet, keep it up
@SpiderJack8 ай бұрын
I like the new code view, seeing you type as it shows on the screen is "chef's kiss."
@wobuntu8 ай бұрын
Saw a few of your videos now and I have to say; pure gold. Immediately subscribed after the first one I watched.
@BaldBeardedBuilder8 ай бұрын
@wobuntu thanks for your kind words! I’m glad you’re enjoying them.
@markohy9samy5652 ай бұрын
I am really learning new stuff from you man thanks ♥
@BaldBeardedBuilder2 ай бұрын
Thanks for watching!
@Zeblab427 ай бұрын
Nice, short, useful video. You have my attention mr bearded developer man.
@BaldBeardedBuilder7 ай бұрын
Thanks for the comment! Glad you liked it.
@Zeblab427 ай бұрын
All jokes aside. I really like your videos. They cover useful topics and in just the right amount of detail. I have consumed a lot of C# material from docs to books to videos, and you still provided great insights and ideas. How did I not come across such a neat soft delete solution in 3 years of research? Perhaps I have too much hair and not enough beard.
@BaldBeardedBuilder7 ай бұрын
@@Zeblab42 Keep coding. The hair will leave. 😁
@SandzakBob8 ай бұрын
What about situation when we use soft delete on a table that has unique constraint on some attribute, etc. email. If we soft delete a record and try to add that record with same email, it would violate the constraint, since this deleted record is not really deleted. Is there some best practice for these kind of scenarios?
@BaldBeardedBuilder8 ай бұрын
That's a REALLY good question. I don't know if there's a "best practice," but I can tell you what I've seen done in the past. If you have a field like that, you could modify the interceptor to also add some unique value after the actual value. Then in your "undo" functionality, remove it. Like "test@test.com-2048210482" where the number is random or a datetimestamp. Then you could just use a regex to remove that ending on "undo." There are probably even better ways, but that's a simple one.
@BaldBeardedBuilder8 ай бұрын
Another option would be to leave the "email" field unchanged and on create, if that record exists, just "undelete" it.
@Eneong8 ай бұрын
@@BaldBeardedBuilder At first I used that way but encountered performance issues when inserting because of record exist check. In the end I found better way to deal with it. For the solution I used postgresql's partial index. In EF core it can be implemented using b.HasIndex(field name).HasFilter("DeletedAt is null") in model config. So deleted entities just were not included in the index. But not sure If every db provider support that feature. I think that case is quite important to be covered somewhere in description or in pinned comment.
@l.b768 ай бұрын
You can create a unique constraint for the email by also including the deleted_at column. With this setup you can create a new user that has the same email as a softDeleted user. Now, this may have other drawbacks, like for example, your requirements change and you need to restore these softDeleted users.
@rankarat8 ай бұрын
Really useful, thanks
@BaldBeardedBuilder8 ай бұрын
Glad it was helpful and thanks a ton for the comment!
@gerb1419Ай бұрын
@Bald. Bearded. Builder. Can you tell me how to design an EF scheme if I need to save large files (blobs) in the MS SQL database? Like 20-50 megabyte files. As far as I understand, FILESTREAM is not supported by EF ?
@BaldBeardedBuilder25 күн бұрын
Hi @gerb1419. Great question for our Discord server. Join us to chat software development and lots more. bbb.dev/discord
@banzooiebooie8 ай бұрын
Cool, great idea. Learned something even if I am a Java developer!
@BaldBeardedBuilder8 ай бұрын
Come to the dark side! 😁
@RikinPatel138 ай бұрын
Que.: You are using DateTimeOffset datatype and you are setting UTC time so it required to use DateTimeOffset to use here?
@BaldBeardedBuilder8 ай бұрын
@RikinPatel13, nope not required. I just prefer DateTimeOffset versus DateTime. It was probably just habit to type that rather than DateTime. Cheers!
@Kimo.Codess8 ай бұрын
I usually just override save changes within the data context. how is that different from the interceptor? what advantage does the interceptor bring?
@BaldBeardedBuilder8 ай бұрын
@kimfom I'm doing a deep-dive video on interceptors this week. For one, there's a lot more of those "hooks" than just SaveChanges. Also, a huge benefit to me, is that I can inject interceptors with DI. (maybe that was a spoiler for next week. 😁)
@Kimo.Codess8 ай бұрын
@@BaldBeardedBuilder yeah thank you I sure am looking forward to that 😊
@williamliu89858 ай бұрын
Never seen this EF technique before, I feel like I've become stronger! 😁
@BaldBeardedBuilder8 ай бұрын
@williamliu8985, just wait until next week's deep-dive video on EF Core interceptors. You're going to feel like a superhero. And thanks for the comment!
@saleem.shaikh8 ай бұрын
Subscribed
@BaldBeardedBuilder8 ай бұрын
Welcome aboard @saleem.shaikh!
@JtendraShahani8 ай бұрын
Is this an extension you use to create new files. Sorry, I always drop and extension, font, or theme question.😊
@BaldBeardedBuilder8 ай бұрын
Don't apologize, I love talking about setups, extensions, shortcuts, etc.! Ask away! To answer your question, VS Code has a CTRL + N shortcut to create a new editor window. Then, CTRL + S will open a save dialog where I can name the file and specify its location. For me, it's faster than using the New File dialog in Visual Studio and keeps my hands on the keyboard.
@BaldBeardedBuilder8 ай бұрын
@JtendraShahani I answered here. 😁
@one.pouria7868 ай бұрын
Is there any way to apply this query filter to all of my entities?
@michaelholloway35478 ай бұрын
I've done something like apply this logic to all entities that implement an interface... (like the ISoftDelete used in this video) but I haven't implemented it with EntityFramework.
@BaldBeardedBuilder8 ай бұрын
I've seen ways to do it, but all of them felt "icky" compared to just adding it to the entities long-form. Some used reflection 🤮, others iterated through the entities and added them. Either way seems like it adds more overhead than I'd want at runtime versus the mental load for a developer to just write them out once.
@one.pouria7868 ай бұрын
@@BaldBeardedBuilder I think we can rewrite reflector version with code generator
@sanglin93878 ай бұрын
soft delete okay but you need a snapshot before and after for auditing purposes
@BaldBeardedBuilder8 ай бұрын
@sanglin9387 maybe. It depends on the requirements. No need to build something that isn't in the requirements. Arbitrarily deciding to add before/after auditing is going to add overhead that may not be needed. Totally a good idea to ask & get clarity before just doing it.
@sanglin93878 ай бұрын
@@BaldBeardedBuilder for accounting system we do before no need because lot of screen just for adjust for mistake user 🤣. new developer think must be prefect but reality end user very ... unthinkable
@SpiderJack8 ай бұрын
Maybe it's just a "bullion" - you mean like soup? The captioning got confused on boolean. 🤣
@BaldBeardedBuilder8 ай бұрын
It's flavorful solution to preserving data.
@PankajNikam8 ай бұрын
I think it's just the gold we are talking about to pay EF not to delete the value 😉😉
@iteospaceАй бұрын
IgnoreQueryFilters if you use many query filters. Its problem
@Krauttrooper8 ай бұрын
Don't forget GDPR you have to delete pii.
@casperhansen8268 ай бұрын
In that case you could have a routine to actually delete records that are marked as deleted once in a while