I Choose THIS Over EF Core - How To Use Dapper in C#

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ม.ค. 2025

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

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

    👇👇👇👇
    Check out Software Architecture with C# 12 and .NET 8:
    amzn.to/3UNYCSo
    👆👆👆👆
    💡 Learn how to program in C#:
    - dometrain.com/course/getting-started-csharp?affcode=1115529_nl-teyzg
    🧠Deep dive on C#:
    - dometrain.com/course/deep-dive-csharp?affcode=1115529_nl-teyzg
    🎁Zero to Hero C# Bundle:
    - dometrain.com/bundle/from-zero-to-hero-csharp/?affcode=1115529_nl-teyzg
    💪 Skill up your refactoring:
    - dometrain.com/course/from-zero-to-hero-refactoring-for-csharp-developers?affcode=1115529_nl-teyzg
    ✉ Subscribe to my free software engineering newsletter:
    - subscribe.devleader.ca

  • @knightmarerip711
    @knightmarerip711 3 หลายเดือนก่อน +2

    Amen bro!

  • @PaulSebastianM
    @PaulSebastianM 7 หลายเดือนก่อน +1

    I also like SQL in my code, but to be honest, also having been a DBA, I also recommend putting even simple SELECTs into stored procedures or at least calling prepare on your embedded SQL statements, this is because SQL servers can cache stored procedure execution plans, as well as prepared statements. This leads to faster executions, especially in the long term, as the same query gets called more and more times. Waits times accumulate and preparing a query every time would slow down the server and consume more resources than needed.

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

      Interesting - do we have to do anything explicit on the commands? I know this is a basic SQLite example, but I thought for MySQL (for example) the database itself handles caching the command if your command text isn't altered?
      I guess the question is: what do you do in C# to "prepare" the command?
      Thanks for the comments 💪💪

  • @emiraksoy1520
    @emiraksoy1520 7 หลายเดือนก่อน +1

    Thanks for this nice content! What about stored procs,views,functions and migrations ? How do you store them on application ? Asking for learning best practices and to benefit from your experience

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

      I almost exclusively use databases for purely storage, so functions generally aren't something I've had to do much of. Essentially, it would involve moving things to the schema creation though.
      But that brings us to migrations 😅 I haven't had to do my own large scale migrations in YEARS so I probably need to put some effort into thinking through how that might look and feel in Dapper, for example.
      In short: I don't have great examples (yet) to refer you to on these with respect to best practices

  • @kapilpatel9379
    @kapilpatel9379 24 วันที่ผ่านมา

    This is interesting, I have found a good channel

  • @simont6439
    @simont6439 6 หลายเดือนก่อน

    What about Dapper.FluentMap? Isn't that a bit less to maintain when things change..?

    • @DevLeader
      @DevLeader  6 หลายเดือนก่อน

      Not sure - haven't seen it yet 🙂

  • @HarleyPebley
    @HarleyPebley 7 หลายเดือนก่อน +1

    Haha, I'm just the opposite: I really dislike having SQL cluttering up my pristine C# code. 🙂 For us, EF works great but we're not doing any heavy DB related stuff. We're essentially using it as a convenient storage medium for specialized document storage where each document is it's own SQLite file.

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

      Hehe yeah I didn't want to frame it as right or wrong, just happens to be the tool that aligns with my style the most 🙂

    • @HarleyPebley
      @HarleyPebley 7 หลายเดือนก่อน +1

      Yep, stuff like this isn't right or wrong; more personal preference and what works best for the domain and team.

    • @pw.70
      @pw.70 5 หลายเดือนก่อน

      @HarleyPebley I find I have to separate my C# from my Blazor, too - it really muddies the water.

  • @iPazooki
    @iPazooki 7 หลายเดือนก่อน +1

    We can use Dapper and EF simultaneously. For reading, it's better to use Dapper as it's faster, but for CRUD operations, EF is preferable.

    • @DevLeader
      @DevLeader  7 หลายเดือนก่อน +1

      Hey, maybe that's the solution to the question around migrations too 🙂

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

      @DevLeader however, we can have two EF contexts and in the read-only context, just enable no tracking, so it won't track any changes as it's as fast as Dapper!

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

    I am also not a fan of EF Core. Honestly, we keep choosing initial speed only to live through a maintenance nightmare. We ultimately choose to make things more complex than they need to be, just because we don't want to write a few lines of SQL or mapping code. All the decisions to use EF that I've seen have increased maintenance costs and bugs. Job security I guess.

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

    My opinion, SQL does not belong in c#. Using schemas, sprocs, views, functions, etc are the way to go. You get better performance plus having these in the db makes reusability so much easier and you know the db items are good because you have already executed the code. You can create a db project and put it in source control. I understand for showing classic vs and ORM in this example it is fine, but for production, keep it clean and separated.

    • @DevLeader
      @DevLeader  7 หลายเดือนก่อน +1

      You're welcome to develop software however you'd like, and I respect that 🙂