Tracking Data Changes in C# .NET

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2024

ความคิดเห็น • 69

  • @fieryscorpion
    @fieryscorpion ปีที่แล้ว +5

    My goodness, how on earth I did not know about this amazing feature until now!
    Thank you for the excellent video, Jason Momoa!

  • @Tymonello
    @Tymonello ปีที่แล้ว +9

    Holy macaroni, that is so amazing. I've been doing that manually, with like one ID for db record, another ID to share between historical objects, and a flag IsHistorical, and while updating an object, then manually copying it, and adding a new one with edited data... this will save me lots of time!

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +1

      This one-liner will take care of that! best of luck!

  • @jwcodendaal
    @jwcodendaal ปีที่แล้ว +8

    Temporal tables are great. I use them when I can. One important note is it requires SQL 2016. In a lot of our CMS systems database compatability is quite old (pre 2016) and we tend to use triggers and audit tables for this kind of thing, very manual compared to temporal tables. Great video. Thanks.

  • @christiantricarico
    @christiantricarico ปีที่แล้ว +1

    Discovering your channel was a gift on this last day of 2022. Temporal table is a great feature.
    I'm a .NET developer since 2006 and I really would like to share my knowledge with others and I really like your style. Hope to find the way in the new year 😀

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +2

      Hey, thanks for your kind words. Would love to have you come on my channel so I can introduce you to my followers/subscribers and hopefully it will be a great start for you to share you knowledge with the world.

  • @bahtiyarozdere9303
    @bahtiyarozdere9303 ปีที่แล้ว

    Eye opening! I have been working with Sql Server and dotnet since 2004. I had no idea there is this feature. We were building custom approaches instead. Thank you!

  • @linguini6232
    @linguini6232 ปีที่แล้ว

    Super cool that you have a fundraiser attached to this! What an awesome way to give back to a meaningful cause.

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว

      This the best thing that happened since I started this channel. I'm really happy I can maximize the benefits people get from this content.
      Thank you for your kind words.

  • @mohamedeffat54
    @mohamedeffat54 ปีที่แล้ว

    Is it just me or is this feature is so amazingly critical that I don't know how the majority of SQL databases I've seen out there live without it, interestingly Postgres does not (yet) officially support this feature.
    I cannot get think of any business no matter large or small that would explicitly opt out of the history and protection this feature gives.
    Thanks for the introduction to this 🙏

  • @marna_li
    @marna_li ปีที่แล้ว +7

    The PeriodStart and PeriodEnd are Shadow Properties in the model. I think that you can access them in queries using a method in the EF class to represent them.
    Like this:
    var contacts = context.Contacts.OrderBy(contact => EF.Property(contact, "PeriodStart"));
    But true, they are normally are not added to the entity for obvious reasons.

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +1

      Good point. thank you.

  • @thanzeeljalaldeen
    @thanzeeljalaldeen ปีที่แล้ว

    this was what i was searching for a project im working on. i implemented this and most of the extra code we had to write was cleaned immediatly. this is great! thanks for the great insight!

  • @lucabriguglia
    @lucabriguglia ปีที่แล้ว +1

    Exceptional! I used a kind of event sourcing approach to do basically the same. How on earth I did not know this was supported out of the box!

  •  ปีที่แล้ว +3

    Great video! I liked this feature because it's a clean way to track data changes. It helps you to keep your code less complex.

  • @minimalist_zero
    @minimalist_zero ปีที่แล้ว

    I had no idea something like this existed. Thank you very much for this.

  • @sherifezzat4983
    @sherifezzat4983 ปีที่แล้ว +5

    Oh my! This is amazing, brother! Let me share my experience with you! We have some old system that we had to code almost the same thing ourselves, by setting a trigger on the main table in DB on update to copy the old data from the main table to another history table i.e h_original_table_name, the history table contains old data, new data, user, hist_dt, and we used this to build a complete an e2e audit and traceability system, plus recovering from failures as you mentioned in the wonderful explanation! 👍 thanks ❤️

  • @hutchm92
    @hutchm92 7 หลายเดือนก่อน

    Excellent information and thanks for sharing. I’m looking to potentially change what I have or use this for another application.

  • @BlazorPlate
    @BlazorPlate ปีที่แล้ว

    Wow! Why we didn't know about this until now. We are gonna apply this concept to our boilerplate SaaS template.

  • @E_G_
    @E_G_ ปีที่แล้ว +1

    This quick sessions&features are great to follow, thank you ☺

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว

      Thank you for watching!

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh 2 หลายเดือนก่อน

    Implemented something like this myself, but better. All column diffs get saved as json into one column, you get date when it was change and admin id, to know who changed it. If you have data changes which you want to track, you usually want to know who triggered the change. specially if you expose an admin backend.

  • @mizanrahman7287
    @mizanrahman7287 ปีที่แล้ว

    This feature looks like Modified Trigger in SQL Server inserted and deleted table. Excellent job!.

  • @loam
    @loam ปีที่แล้ว

    Woah, guess I fiound one more channel to become my favourite C# channel amongst a few others 🙂

  • @billias28
    @billias28 4 หลายเดือนก่อน

    Very nice presentation

  • @abdchuhan
    @abdchuhan ปีที่แล้ว +1

    That works only for MS SQL Server, for other databases you have to do this Audit manually.

  • @akshay_zz
    @akshay_zz ปีที่แล้ว

    Saw two videos of yours. Learned two new things. Thanks

  • @shawn301287
    @shawn301287 ปีที่แล้ว

    Lovely!! You are making my life easy, one line of code at a time..

  • @soucianceeqdamrashti8175
    @soucianceeqdamrashti8175 ปีที่แล้ว

    This was a really good tutorial, learned a lot! Nice work Hassan!

  • @cdrbvgewvplxsghjuytunurqwfgxvc
    @cdrbvgewvplxsghjuytunurqwfgxvc ปีที่แล้ว

    Thanks, and also for your work on odata!

  • @awaisshabir9169
    @awaisshabir9169 ปีที่แล้ว +1

    Wonderful session

  • @jlzsantos
    @jlzsantos ปีที่แล้ว

    Very cool, It's a good example, thanks for sharing.

  • @GameDevNerd
    @GameDevNerd ปีที่แล้ว +1

    I just started encountering this channel on YT, hadn't heard of it before, but it seems to cover some "big data" and "enterprise" scenarios I'm not familiar with and would seriously enjoy learning. I've been programming for a long, long time but I couldn't possibly (ever) learn _everything_ haha, nobody can. And there's something about listening to another engineer with expertise in other fields talking about how they do things and solve problems that I just _really_ love and admire. Looks like I found another good channel to add to my "backlog" for future YT-watching sprints, haha 😁
    I really, _really_ wanna find time to start making serious videos of my own, because I have a _lot_ of things I could share to add value to people's careers, education and learning paths, etc, but my actual work for my real job keeps me so busy that it's hard to set aside time and ever make myself record and edit! And I've been promising friends and colleagues for a while I was gonna do it ... people want me to make videos about advanced interop and writing wrapper libraries, "hacking" .NET assemblies and using IL and native asm for cool stuff, creating DSLs and lexer/parser/compiler tools, real-time 3D stuff with DirectX 12 and game engine architecture, there's like 100 things I kinda "owe" people videos on, lol. This video gave me a bit more inspiration to get to it today ... I've gotta start soon!!! 🤨

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +2

      Hi Aaron, we could start doing sessions together - I don't edit my videos, it comes as is. I usually tell people there are content creators and there are people who just make content - I'm the latter haha.
      Let's find time to get to know each other and show the world some of your magic.

    • @GameDevNerd
      @GameDevNerd ปีที่แล้ว

      @@HassanHabib that would be cool, man, I'd definitely enjoy that. You on Discord?

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +1

      @@GameDevNerd Of course, this is my Discord: Hassan Habib#8097

  • @fahimahmedali
    @fahimahmedali ปีที่แล้ว

    That's an amazing feature. Learned something new today.

  • @Ferenc-Racz
    @Ferenc-Racz ปีที่แล้ว

    Thank you for this video. Thank you for your knowledge sharing! I appretiate it.

  • @Albertkallal
    @Albertkallal ปีที่แล้ว

    Only thing to add is that you can add + create a temporal table for any table - and that includes when you not using EF and a database first approach as in this video. So, even if you using an existing web site, or even say ms-access against a sql server table, you can add + enable a temporal table, and no code changes are required at the code level, or even if 2 different systems use the same database. so, to be clear, this is a SQL server feature, and one that not really tied to code or even when using a database model - no requirement exists to use this feature with models - it works even if using say ODBC to sql server.

  • @ThiagoCoppi1
    @ThiagoCoppi1 ปีที่แล้ว

    Amazing feature man! Thanks for sharing!

  • @mohammedelsuissey1745
    @mohammedelsuissey1745 ปีที่แล้ว

    Hello Hassan
    Great work man, thanks
    BTW, ef.tools package includes the ef.design package :)

  • @felipesakuma9882
    @felipesakuma9882 ปีที่แล้ว

    I tried creating a column for LastModifiedBy and OperationDone using Entity Framework but couldn't make it work. Am I missing something or it is impossible to do so with EF only? I understand it is possible doing so with custom methods that write to a history table, but I prefer using native code from EF

  • @anilkumar8753
    @anilkumar8753 ปีที่แล้ว

    Temporal tables not available in SQL server standard edition.

  • @maltebeck514
    @maltebeck514 ปีที่แล้ว

    Hey, nice video! Is there an equal simple way to create a „bitemporal“ table? That means track not only date of change, but also date of knowledge, so you know which history was known at a given date?

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว

      Please elaborate. I don't fully get what you're asking.

  • @zimcoder
    @zimcoder ปีที่แล้ว

    How would you take advantage of this if you are using the repository pattern on top of EF?

  • @CesarBonezzi
    @CesarBonezzi ปีที่แล้ว

    Hassan, Thanks very much for this excellent introduction of Temporal Tables in EF. I will be exploring this further in the next couple of days. First, I was wondering if you come across anything about the performance hits from temporal tables to the system. And second, in a system that is of high traffic generating many entries on the temporal table, how are these managed in terms of how much space they occupy, and is it possible to compress the temporal table, to minimize storage usage.

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +2

      Hi Cesar,
      Thank you for your kind words. I appreciate you.
      I haven't analyzed the performance for Temporal Tables yet - might be a good session to do however.

  • @bhatsanket
    @bhatsanket ปีที่แล้ว +1

    What about turning on CDC... This way the orm is not burdened with this?

  • @razbasnet173
    @razbasnet173 ปีที่แล้ว

    Holly shit thank you for sharing.😊

  • @james69911
    @james69911 ปีที่แล้ว

    good job! amazing function, and I wonder if i update student by using raw sql command, will this function still can track data changes? thank you for sharing this information.

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว

      Yes it should - give it a shot

  • @karthiks4347
    @karthiks4347 ปีที่แล้ว

    Well, i think the dates are not coming because the students class has no columns for dates. I think we must inherit the students class into a new class having both the date columns that is used to iterate though!! My hunch is, this may work.

  • @mahmoudakeel8246
    @mahmoudakeel8246 ปีที่แล้ว

    What is the best monitor for developer from your opinion?

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว

      I like this one: SAMSUNG 49” Odyssey G9 Gaming Monitor

  • @GarethDoherty1985
    @GarethDoherty1985 ปีที่แล้ว

    Is there a way for it to also track who changed the data?

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +1

      If you add fields like CreatedBy and UpdatedBy you certainly could.

  • @petargeorgiev2738
    @petargeorgiev2738 ปีที่แล้ว

    Is this killer of Event Sourcing?

  • @prithvisingh2593
    @prithvisingh2593 ปีที่แล้ว

    wonderfull

  • @yaKaiZen
    @yaKaiZen ปีที่แล้ว

    🙏

  • @novaploca2080
    @novaploca2080 ปีที่แล้ว

    Wow

  • @akhilbandari629
    @akhilbandari629 ปีที่แล้ว

    Great to know

  • @TheZigsDk
    @TheZigsDk ปีที่แล้ว

    Jesus christ, can I buy you a coffee or something?

    • @HassanHabib
      @HassanHabib  ปีที่แล้ว +5

      Give it to the very first homeless person you run into tomorrow (I used to be homeless)

    • @bootsector13
      @bootsector13 ปีที่แล้ว

      give it to me

  • @ed-ou812
    @ed-ou812 ปีที่แล้ว

    Don’t lock it down to students. Make this a generic solution to data changes so it is easily reusable.