Will This New EF Core Feature Be The End Of Dapper?

Поділитися
Вставка
  • Опубліковано 11 гру 2024

КОМЕНТАРІ • 220

  • @MilanJovanovicTech
    @MilanJovanovicTech  Рік тому +5

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

    • @kumailn7662
      @kumailn7662 Рік тому

      what about the performance matrix between the two framework?

  • @dave7244
    @dave7244 Рік тому +29

    Betteridge's law of headlines. "If a headline asks a question then the answer is almost always no".

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      That's an interesting law, never heard of it before! 😁
      Although I believe this feature can solve most Dapper use cases in practice.

    • @flygonfiasco9751
      @flygonfiasco9751 Рік тому

      I always think the answer is always “maybe but probably not”

    • @dave7244
      @dave7244 Рік тому +1

      The point I am making is that it would be better to tell us what the new feature is rather than click bait headline

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      @@dave7244 Then a lot less people would click. I'm sorry that's how the algo (psychology) works 🤷‍♂
      I need to battle with getting view & providing information at the same time.

    • @caseyworth9701
      @caseyworth9701 Рік тому +2

      ​@@MilanJovanovicTechgot me excited, but didn't take long to realize the answer is no for me. For me dapper is optimal for performance and control. I created a wrapper that handles connections and turns most common use case of getting a collection or executing a command to a single line function.

  • @peterkulik5943
    @peterkulik5943 Рік тому +19

    I would have solved this case with Dapper by executing 2 selects using the QueryMultiple method.
    It would have still been one roundtrip, and there would be no need to add unnecessary complexity to separate the result data...

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      It's one round trip on SQL Server since it has MARS. It won't work the same on PostgreSQL, for example. And the mapping can be solved with an extension method + mapping function.

    • @reikooters
      @reikooters Рік тому +2

      ​@@MilanJovanovicTech To clarify his comment: In your video, your query returns 1 result set with 4 columns, with the value in the first 2 columns being duplicated for every LineItem returned. Peter is saying he would instead write a query with two select statements. So from the database he would receive 2 result sets - the first has 1 row with 2 columns - the orderId and customerId. The second result set has 2 columns - the lineItemId and the lineItemPrice. This removes the duplication of orderId and customerId that you had in your example. To return an Order object with its LineItems, you just assign the list of LineItems from the 2nd result set to the LineItems variable of the Order class - this is what he meant with removing complexity of separating the data. As per his comment, writing one sql string containing both selects is still only making one trip to the database. This is the way I'd do it with Dapper as well.
      If you were selecting multiple orders as well as their lineitems, and want to return a list of orders, it gets a little trickier. In that case, I'd still do it the same way as in Peter's comment - first create the list of orders from the first result set, but then to assign the LineItems to each order, I'd loop through the Orders 1 time to create a dictionary of Orders, then loop through the LineItems and use the orders dictionary to add each LineItem to the appropriate Order's LineItems list.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      @@reikooters I understood that perfectly well 😅 I know how JOINs work...
      And I said that's only possible - fetch everything in one round trip - on SQL Server, and not other SQL providers.

    • @reikooters
      @reikooters Рік тому

      @@MilanJovanovicTech Ok now that I re-read your comment that makes sense. When you said MARS it threw me off as Multiple Active Result Sets is a setting that allows one connection to the SQL server to be used for serving multiple requests at once, which is a bit different topic. But I understand now that what you meant was that other databases can't return multiple result sets in a single batch like described earlier. Sorry for the confusion.

  • @jeroen7362
    @jeroen7362 Рік тому +6

    This inline sql is a way to create unmaintainable code. Just like stored procedures. If you have lots of this and you want to change your database schema your build works but everything breaks when you run it. the strength of EF is that all code is typed, no magic strings, so changing an enitity class will break all using code during local development. Reducing bugs by a lot.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      You build works, but your tests should definitely fail

    • @jeroen7362
      @jeroen7362 Рік тому +2

      ​@@MilanJovanovicTech Who has the budget to have 100% code coverage? it is much better to fail in the build or before you even try to build, you ll have the errors in the ide. Choosing reliable ways to code stuff saves you from a lot of unneeded bugs. Inline SQL (and stored procedures or magic strings (use nameof() instead of the "name"!) has been one of the biggest problems in code maintainability and reliability that i have encountered. I strongly advise against using it, its bad practice in my "book".

    • @akrotiri3246
      @akrotiri3246 6 місяців тому

      it can be more managable with using nameof's instead of typing them as strings but still writing raw sql is terrible idea imho, also this is very low code, i don't like to have my objects have id's at all. just have actual objects that those id's point to.

  • @rustamhajiyev
    @rustamhajiyev Рік тому +33

    Finally we have both approaches united under one library 🎉 Waiting for performance benchmarks 😉
    Thanks for the content! 😃

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +3

      I'm not sure what to expect. Dapper may still have an edge though. We'll see 😁

    • @GregorNanger
      @GregorNanger Рік тому

      @@MilanJovanovicTech I hope it will have an edge. I became so comfortable with Dapper, that I do not to rewrite things. But if EF will be faster just fo microsecond, than I will not sleep :-)

  • @Bennevisie
    @Bennevisie Рік тому +7

    It would be useful to give a brief explanation of the use case you are implementing beforehand. Some of us struggle to follow if we don’t know where you are heading.

  • @BovIne-gz3dz
    @BovIne-gz3dz Рік тому +2

    Your channel is a blessing to all .Net developers! All power to you reaching 50k subs and beyond 💯

  • @Kingside88
    @Kingside88 Рік тому +3

    working with childs was, is and will always be a problem.
    Dapper comes with the "splitOn" solution where you have to define at which column you want to split. After that you have to add the childs in a separate dictionary.
    RepoDB define for itself to not handle childs.
    Now this EF 8 Solution is to be honest also cluncy. You have to define a flat-object to group it after that.
    It may be not the fastest soulution but EF with just saying .Include(...) gives by far the best readable solution for developers.
    Saving childs is by the way possible by define user-defined-types for SQL Server and pass the whole child as parameter. And EF provide also a great solution.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      It's not a solution, just something I came up with quickly. I'm sure there are better solutions

  •  Рік тому +4

    Dapper can do map one to many relations.. you don't need to create the joined line record, and still, dapper needs no initialization like EF does with dbcontext generation, so in serverless functions (aws lambda or azure functions) it still gives you a big edge...

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      But in the scenario where you're already using EF, this does solve many scenarios.

    •  Рік тому

      @@MilanJovanovicTech agreed on that

  • @thefrugaldeveloper140
    @thefrugaldeveloper140 Рік тому +2

    Hi Milan, really appreciate the time and effort you put into this stuff. I really wish there would be more content on some of the other tools out there.

  • @ardavaztterterian1211
    @ardavaztterterian1211 Рік тому +15

    I'm a bit iffy about this. I consider hardcoded string queries a code smell in my projects. I would rather lose a couple of nanoseconds of performance than have hardcoded queries.

    • @isen1
      @isen1 Рік тому +1

      Im a beginner and just asked my self the same question. This was one of the first statements the Database teacher told us NOT to DO?

    • @NikolasMauropoulos
      @NikolasMauropoulos Рік тому +2

      We do have huge databases (>1TB), having projections of specific data is crucial for the microservices that interact with these databases. Not everything can be an entity, and you certainly some times want something more custom. While i understand why you would want a typed query, sometimes you gotta go raw.

    • @PhuongNguyen-zb2en
      @PhuongNguyen-zb2en Рік тому +1

      Sometimes the query compiles by EF Core is really slow, and we need to make it right by SQL query instead. Some features in my current project have this problem so if someone new to EF Core, please keep in mind it is really great that ORM can do so much things for us, but sometimes SQL query is not that bad

    • @victor1882
      @victor1882 Рік тому

      Sometimes it's not about performance, some specific feature might not be translated yet by the EF Core provider

    • @thebig9720
      @thebig9720 Рік тому +5

      Would a Stored Proc be better?

  • @rr.vasconcelos
    @rr.vasconcelos Рік тому +2

    I'm studying English a lot to be able to better understand your teachings! Your videos are great

  • @alexmarahovsky263
    @alexmarahovsky263 Рік тому +3

    I don't want to disappoint you but EF was always able to compete with Dapper! You just need to compiled (pre-compiled) linq query.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      That would be too much work just to be on the same level. Don't you think so?

  • @joga_bonito_aro
    @joga_bonito_aro Рік тому +3

    I hope this will get a query builder... I'm not too keen on writing big strings for querying in a code first approach.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +3

      Learn SQL 🤣

    • @joga_bonito_aro
      @joga_bonito_aro Рік тому +8

      @@MilanJovanovicTech that's not the problem i mainly have. The problem for me is that it's hard coded and if, for some reason, someone changes the names of the properties, you have to manually change the occurrences by hand ✋

  • @aimene_.
    @aimene_. Рік тому +4

    With Dapper or EF, never write SQL Queries in the code. Use stored procedures

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      How is that any better? This way at least I have them in source control

    • @aimene_.
      @aimene_. Рік тому +1

      @@MilanJovanovicTech This is the work of a DBA not a developer. SQL is more complex than people think, there's a lot of things to think to get a better performance in SQL.. there's also tools in SQL to track performance and schema of a request.
      And of course you can export a Schema File .SQL and you put that in Git to track changes.
      Actually it's a simple request you do, but imagine when you work for a big company who have some requests of thousands of line.. it's better and safe and readable to put that in Stored procedures.
      In my opinion there's two ways. Use code first like EF or use Dapper or EF with stored procedures.
      Remember that as a Developer you should never assume risques of a DBA. Because you are not paid for, and you can be in a trouble if something is wrong in production.
      Also, every developer should learn SQL server, no one can be a good developer without that.
      But remember to let everyone assume his job. Because he knows How to do it in a good way.

    • @harag9
      @harag9 Рік тому +1

      @@MilanJovanovicTech Really? You don't know how much better Stored procs are over SQL statements....

    • @HMan2828
      @HMan2828 Рік тому

      That defeats the purpose of the ORM... With an ORM like EF you get platform independance, which means if you decide to migrate to a different DBMS, all you need to do is switch DB provider and connection string. If you write your application with a bunch of stored procs, you have to rewrite them. I work on ERP data systems with hundreds of tables and millions of records, the only stored procs or db triggers we use are for very specific things, like audit tasks, access control or user rights management, maintenance tasks, etc... Things that would be too complicated to do purely in EF, basically.

  • @Brendan2Alexander
    @Brendan2Alexander 10 місяців тому +1

    Very interesting, thank u! If we are getting nit-picky, there is the overhead of provisioning a dbcontext instance from the db pool every time you need to run a query. Whereas using dapper I would presume it wouldn't rely on as much resources, tho am only speculating here. Will look forward to seeing your benchmarks video!

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому +1

      The performance difference is quite minimal with the recent versions of EF

  • @kylegivler8372
    @kylegivler8372 Рік тому +1

    thanks for sharing

  • @rustamtaov1510
    @rustamtaov1510 Рік тому +2

    An awesome video, an awesome feature and awesome explanations! I've worked with Dapper for 2 years so it looks so intresting. You also can group data via sql script and miss linq grouping and selecting data

  • @antonmartyniuk
    @antonmartyniuk Рік тому +1

    Wow, that can truly put the need of the Dapper back. Also in this video a nice comparison of 2 libs can be seen and how much easier to query data using high level EfCore features and you get the model you need straight away

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      I didn't try composing the IQueryable further, but if that's possible it will be pretty good

  • @codeheaven559
    @codeheaven559 Рік тому +1

    awesome stuff.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Thanks :) I also released a video this week that covers this feature in detail

  • @MrNickP
    @MrNickP Рік тому +3

    My problem with this approach in general is that you are returning a lot of duplicated data. In you example you are only returning a few fields from the order but what if you need more? Every field you add is duplicated for each line item. 1000 line items means you just transferred and loaded 1000 duplicate fields that are going to discard.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Then run two queries 🤷‍♂️

    • @joeng3385
      @joeng3385 Рік тому +1

      @@MilanJovanovicTech why not put the group by and aggregates in the SqlQuery ? so they are done at the db server side and save the network traffic volume at the cost of server CPU consumption.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      @@joeng3385 And what do you get back from the DB?

    • @davidmartensson273
      @davidmartensson273 Рік тому

      @@joeng3385 You do not want an aggregate of the rows, you want all the rows so either you would need to run two queries, which adds overhead, or you do as the example in the video.
      I do not know if EF_Core can use multiple results, but that would be a lot more complex query on the SQL side so unless its a lot of data from the order its probably not worth it.
      And if it really is, then you probably want to make it into two separate queries and merge in C# instead

  • @DrHeinzDoofenshmirtz
    @DrHeinzDoofenshmirtz Рік тому +2

    Writing short subtitles in the video seems a bit redundant when UA-cam can already do it automatically. Why not write the custom subtitles there?
    Personally I find the in-video too-quick subtitles distracting.

  • @johannesmogashoa1320
    @johannesmogashoa1320 Рік тому +2

    Man this is the video I tell you. Looking forward to seeing what the benchmarks reveal especially now as my team will be doing a rewrite of one of our projects and we are still debating on whether to go EF Core or Dapper or both. 👀

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Underwhelming, to say the least. Nick just did a benchmark video, and it's slower than Dapper and pretty much on par with EF LINQ.
      I'll do another benchmark video in a few months, if I see some improvements are made to this feature.

  • @TheMdecima
    @TheMdecima Рік тому

    I just find you searching about ddd, Great content, thanks

  •  Рік тому +6

    If you're making a performance video, please also include linq2db with the different ways of writing the queries and optimizing it. At least that would be very interesting for me as I have used it in some projects, and like the abstraction level they have chosen (in between standard EFCore and Dapper).

    • @grzegorzfedoryka5045
      @grzegorzfedoryka5045 Рік тому +1

      +1. However I found linq2db creating queries which results were incorrect. However I use it for some features (window functions support, custom aggregate functions support, some patterns that efcore can't handle etc)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I'll consider it. But I haven't used linq2db before 🤔

    • @shanerogers-nz
      @shanerogers-nz Рік тому +4

      If/when you do the comparison between EFCore 8 and Dapper. Can you include both the 'normal' linq approach vs the new raw SQL version in EF 8. I'd be interested in not only the time difference between EF and Dapper. I'm also very interested in understanding the different in times between the two EF approaches (both using EF 8 for a fare comparison).. and keep up the good work mate.
      I ask as if the performance isn't 'worth' the extra code and hands off SQL vs LINQ approach.. readable and compile safe is my preferred option. I do agree that projection and other approaches to reduce the effort to produce results, at scale. The extra $$ to gain from unreadable code maybe not worth it. Except when it is 'worth' it.
      Nice work!

    • @ALOKSHARMAMD
      @ALOKSHARMAMD Рік тому +1

      +1 for mentioning linq2db i use it to handle bulk scenarios where we have to push tonnes of data rows around or when some special queries ef cannot handle like projected unions.

  • @EbrahimHassan
    @EbrahimHassan Рік тому +1

    this great, as i know dapper does not have IQueryable return , i think this is a good advantage for the EF core 8, what do you think?

  • @tibba69
    @tibba69 Рік тому +1

    I really wish we could use EF Core but as far as I know, it does not support the database my company is stuck using - IBM for i or DB2 iSeries (or whatever it’s called these days).
    To make it worse we are stuck on version v5r4! 😢
    Does anybody know if EF Core can be used for this as I haven’t been able to find anything for years.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      What about this: www.ibm.com/docs/en/db2/11.5?topic=adonet-data-server-provider-net-core

    • @HMan2828
      @HMan2828 Рік тому

      Nuget package is IBM.EntityFrameworkCore, been working for at least 2 years AFAIK...

  • @malekan59
    @malekan59 Рік тому +1

    Great video, thanks. Is it possible to achieve something like Dappers QueryMultiple in EF Core 8?

  • @michelchaghoury9629
    @michelchaghoury9629 Рік тому +1

    Was Theme are you using?

  • @berathebrain
    @berathebrain Рік тому +2

    I switched from EF to Linq2DB and never looked back. Can you compare the two with regards to ease of use, features and performance for some complicated queries? I am interested in your opinion.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I'll add that to my topic list 😁

    • @HMan2828
      @HMan2828 Рік тому

      Linq2SQL is fine if all you are doing is ad-hoc queries, but EF gives you atomic operations, proper complex type support, database generation from the model, loose coupling through dependency injection, etc...

  • @rade6063
    @rade6063 Рік тому +2

    We will see when performance benchmarks come around, but if it is the same as dapper it could absolutely kill it

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      I expect it to be close, we'll see 😁

    • @reikooters
      @reikooters Рік тому +1

      Even if they're close, I'd probably still keep using Dapper. However, if they can get EF to use source generators rather than reflection, that would change the conversation.

    • @rade6063
      @rade6063 Рік тому

      @@reikooters They probably will sometime soon since more and more libraries use source generators now

  • @frankbanini8884
    @frankbanini8884 Рік тому +1

    Good video once again, But can you do a video with benchmarks of the performance to illustrate your point. Thanks

  • @browaruspierogus2182
    @browaruspierogus2182 Рік тому +2

    but that's available in old EF6 not core.... lol didn't know EF Core was so limited

  • @Sergio_Loureiro
    @Sergio_Loureiro Рік тому +2

    So much thought put into ORM frameworks, and in the end the developer still needs to write SQL queries by hand...

  • @codelord9031
    @codelord9031 11 місяців тому

    How is the one-line LINQ statement AsNoTracking by default ?

  • @Chris-zb5nm
    @Chris-zb5nm Рік тому +1

    You sure it's a new feature? This was already in the entity framework like 10 years ago! They're just brining it back to the Core.

  • @krystian5858
    @krystian5858 Рік тому +1

    Would that mean that we finally can get dynamic queries (for example dynamic sorting) out of the box, without writing custom expressions or referencing 3rd party packages?
    Can I combine "classic" lambda-style LINQ queries and have dynamic orderby with this?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I have not tried it, but since this returns an IQueryable in theory it should be possible. Going to explore the feature more to see if it's possible.

    • @HMan2828
      @HMan2828 Рік тому

      What benefit do you gain from dynamically sorting server side instead of just sorting the results of the query client side?

  • @ekleziast1
    @ekleziast1 Рік тому +1

    А тут на 39 строке в самом конце нельзя SingleOrDefaultAsync поставить? EF из за ToListAsync разве не должен по всем записям пробежаться?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      You would get strange results - it's a JOIN which returns multiple rows from the DB. Single would only fetch the first row. Right?

  • @Manikandanmurali-h7r
    @Manikandanmurali-h7r Рік тому +1

    EF Core's new feature may make it easier for developers to write raw SQL queries and map the results to objects, which was previously a strength of Dapper. However, this feature does not replace Dapper entirely.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Not yet, for sure. But as more features are introduced, we'll see how this will evolve.

  • @CeleChaudary
    @CeleChaudary Рік тому +1

    Thanks for talking clearly, we all foreign can understand you perfectly!!!

  • @Noor-hd5nf
    @Noor-hd5nf Рік тому +2

    Great video Milan. I'm planning an app and I was thinking about using Dapper for reads and EF Core for writes. If this new feature in EF 8 has the same performance as Dapper I will consider it in the future.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      I'll let you know as soon as I do the benchmark 😁

    • @JohnPeter-yf5jf
      @JohnPeter-yf5jf Рік тому

      dapper is always faster
      If you use store procs it’s even faster.

  • @LCTesla
    @LCTesla Рік тому +1

    This is more like EF Core admitting defeat to Dapper by becoming like it.

  • @EdubSi
    @EdubSi Рік тому +2

    Its more verbose, includes table Details, has a Bug (no items returned throws) and most likely isnt faster. Not sure it's worth the cost of loosing the Advantage of using EF Core even for Performance critical paths. Benchmarks is the first thing we should have done 😅

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I'm pretty confident it'll be more be performant, but I'll let the benchmarks prove me wrong 😁

    • @davidmartensson273
      @davidmartensson273 Рік тому

      On the other hand, an order without any items sounds like broken data to begin with :)
      But this is an example, probably not production level SQL code or mapping.

    • @dsvechnikov
      @dsvechnikov Рік тому +3

      Nick Chapsas made a video about this feature and he did benchmark it. TLDR: Dapper is still faster and uses less memory. Going back to his earlier videos where he did compare dapper vs regular EF, raw sql in EF looks not that different from regular linq queries. At least for now.

    • @HMan2828
      @HMan2828 Рік тому

      @@dsvechnikov If you precompile and cache your EF queries, there is basically no difference in performance, or memory usage...

  • @mohamadhelaly4979
    @mohamadhelaly4979 Рік тому +1

    Thanx a lot,
    It's a really nice feature explanation.
    Keep going, you are awesome 🔥

  • @Leo-tf7gu
    @Leo-tf7gu 8 місяців тому

    A bit late, but I like Insight.Database library a lot due to its excellent and complex object mapping features. In this example, with InsightDatabase there would be no grouping necessary.

  • @nicolasundiano8406
    @nicolasundiano8406 Рік тому +1

    Hi Milan, is there a way that we can constraint the IApplicationDbContext only for AggregateRoots? Because i like using this feature instead of repositories but i want to constraint that only the ARS can access the iappdbcontext

  • @robertraboud1466
    @robertraboud1466 Рік тому +1

    couldnt this already be done with EF Core Views?

  • @SureshKumar-rz7dn
    @SureshKumar-rz7dn Рік тому +1

    Really nice video .. but when i use long string sql queries inside the code I feel little ugly the code looks . Is there any better way for that 😂

  • @amrosamy8232
    @amrosamy8232 Рік тому +1

    EF Supports this feature, I'm not sure if EF core didn't support it before EF core 8

    • @kurtcochran9170
      @kurtcochran9170 Рік тому +1

      This is what I was going to say. I don't understand why they removed this feature in the first place. Before 8, EF Core made us add the unmapped entity as a dbset, which seems silly. I am glad they're putting it back, though; I have a project that needs to be moved to .NET Core, and this solves one of the major problems.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      There's probably a good reason for that 🤷‍♂️ Or just lack of engineers to ship this until now.

  • @WillmanForever
    @WillmanForever Рік тому +1

    Hello Milan! interesting video, I am currently using Dapper and SqlKata and extending some methods for SqlKata to be able to use them with my entities without having to write the raw query, for example:
    var result = _repoQuery.GetQuery()
    .SelectRaw(columnNames)
    .Where(nameof(TemplateType.ClassId), classId);
    I hope to be able to do something similar with this new feature. Thanks for your content!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Why not just write SQL? 🤔

    • @WillmanForever
      @WillmanForever Рік тому

      ​@@MilanJovanovicTechby example: names of tables, schemas or columns are different in my models and database

    • @--9884
      @--9884 Рік тому

      ​@@WillmanForeveruse alias..

  • @YahushuaMessiah777
    @YahushuaMessiah777 Рік тому +1

    We're not allowed to use inline sql like that we can only use parameterized queries so how can you do what you just did but parameterized?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      It is parameterized 😅 It "looks" like an interpolated string, but the argument is actually converted into a SQL parameter. That's how the FromSqlRaw methods work.

    • @YahushuaMessiah777
      @YahushuaMessiah777 Рік тому

      @@MilanJovanovicTech oh nice.

  • @gmdias0_
    @gmdias0_ Рік тому +1

    I didn't understanded everything, maybe because I'm new at C#, but I think I could deal better with the second approach using EF 8.

  • @alexandrtsurkan
    @alexandrtsurkan Рік тому +2

    Well it does not look like dapper replacement. What if you need to get more than 1 dataset from db, you would join all them to 1 result dataset? Also what if you need to put as a parameter user defined data type? What if you need to get back dataset plus return value from stored procedure?
    I moved to dapper about 8 years ago, and do not see alternatives for it at least on my project. I mean ef even not close to all dapper functionality.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Multiple result sets (or MARS) is a SQL Server specific feature. In any other case, it's just multiple SQL queries in multiple round trips.

  • @muhammadtariq8323
    @muhammadtariq8323 Рік тому +1

    What about parameterize query ? Is it safe from SQL Injection ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      The example I showed is parameterized

    • @harag9
      @harag9 Рік тому

      @@MilanJovanovicTech How is it it parameterised, you just used string interpolation to inject the string into the SQL string. that is not parameterised.

  • @maestrowilliam
    @maestrowilliam Рік тому

    code in 189% it's look very clear. All other thing are almost imposible to see.
    Then we need to see it full screen and that make the code to big.

  • @oguzhankomcu2031
    @oguzhankomcu2031 Рік тому +1

    I have a process such as adding 100 thousand records to my MsSql database at once, using an entity framework with a loop. This works successfully at low numbers, but is there any timelout in such large numbers? How can I make this happen in a healthy way?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Bulk insert maybe?

    • @oguzhankomcu2031
      @oguzhankomcu2031 Рік тому

      @@MilanJovanovicTech This really works. It really surprised me how fast it added 100k of data. Thanks.

  • @AbNomal621
    @AbNomal621 Рік тому +2

    I was interested in the new feature of EF, but do you REALLY believe Dapper will be displaced so easily? If so, you are incredibly naive. No like or subscribe here. Perhaps if you drop the click bait, and have a performance comparison. But “probably” won’t begin to sway others. And the feature is far from those I use regularly in Dapper.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Dapper isn't getting many new features. EF is rapidly innovating. Give it some more time :)

  • @nawarali1912
    @nawarali1912 Рік тому +1

    Hello milan thanks for you efforts, one of the best content creator in my opinion
    i have a question let's say that in the same app i want to add the categoriesto the product
    then, as in the diagram you provided serveral videos ago what should it be defined as an aggregate root or it's an entity
    and if it's an entity how can i add the management endpoints to it like add delete and so on because it will belong to some aggregate root,
    on the other hand if it was an aggregate root
    i tried to add a list of it's ids to the product aggregate but couldn't figure out how to configure it with ef
    can you make a video about simillar scenarios or something like that
    thanks again ♥

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      The problem is you're thinking about it from a CRUD perspective.
      A Category is most likely a standalone entity in your domain.
      Products can belong to one or more categories.
      So just configure a one-to-many relationship on the Product side.

    • @nawarali1912
      @nawarali1912 Рік тому

      @@MilanJovanovicTech i see that make sense thank you

  • @abigfatkittycat
    @abigfatkittycat Рік тому

    Slapper is a cool library that can do that grouping of child records based on ID and return a complex type that pairs very well with Dapper. You just get a list of dynamics from Dapper and feed it to Slapper and if your fields are named right (or you can manually teach it a mapping) it will handle the mapping for you. Works great if you change your types, no need to refactor the mapping code. If EF Core 8 supports reading results from the DB into dynamic it should pair just as well.
    Overall, if you prefer the Dapper approach I don't see this as a reason to stop using Dapper. It's just copying Dapper and letting that functionality exist alongside traditional EF. If you don't like EF to begin with (like me) - why not just keep using Dapper?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Of course. I'm an EF fan, but I don't mind Dapper at all. I'd prefer to have everything in one library.

  • @rrsouzaf
    @rrsouzaf Рік тому +1

    hi. I think this type of query can lead to sql injection. is there any way to do prepare statement like dapper does?

  • @02244
    @02244 Рік тому +2

    Why do you need EF Core to write pure SQL?
    The power of EF Core is to write strongly typed queries and to detect errors in a query at the compile time.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      There's also the flexibility to write raw SQL for performance reasons

  • @wellyngtond2
    @wellyngtond2 Рік тому +1

    There is no reason to use dapper now, 2 weeks ago I was wondering about it, how was possible I cannot to make a raw query without to specify an entity dataset. The Microsoft God listened my thoughts .

  • @yasser2768
    @yasser2768 Рік тому +3

    Dapper is lightweight
    Not just about the features

  • @saulolima6874
    @saulolima6874 Рік тому +1

    Amazing!

  • @michelchaghoury9629
    @michelchaghoury9629 Рік тому +1

    very informative can you make a tutorial for developers new to C# and NET please?

    • @mylesdavies9476
      @mylesdavies9476 Рік тому +1

      There are plenty of decent channels out there, Milan makes great content for intermediate developers looking to advance their skills

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      As Myles said, there are awesome channels out there and my target audience are is for more advanced engineers 😁

  • @01000110011011000110
    @01000110011011000110 Рік тому +1

    Its nice to have but i dont see that replacing dapper...
    No dapper project ever broke on an upgrade, cant say the same for the ef projects - especially with posgres this was a nightmare for some projects.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Maybe. But if you're already using EF, it solves many use cases that you would previously use Dapper for

  • @mahdignb
    @mahdignb Рік тому +1

    Great content. I have one question and that is why you used record instead of class in this video?😅

  • @FabioMaulo
    @FabioMaulo Рік тому +2

    This thing is somethong you can do in NHibernate since around 20 years.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      EF Core is a bit late to the party

    • @FabioMaulo
      @FabioMaulo Рік тому +1

      @@MilanJovanovicTech what I mean is that "EF Core Feature Be The End Of Dapper" is not a good title. They are all tools, is similar to saying that because you now have philips screwdrivers you don´t need plain screwdrivers.

  • @AlfredoPinto
    @AlfredoPinto 10 місяців тому

    Well, it seems that now is better than Dapper but not than RepoDB

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому

      RepoDB isn't widely adopted

    • @AlfredoPinto
      @AlfredoPinto 10 місяців тому

      @@MilanJovanovicTech So do you mean that just because it is not popular enough for you it doesn't matter that is better?

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому

      @@AlfredoPinto Did I say that? No. So, why place words in my mouth? Weak argument... Any speed improvements these ORMs can make will be on the processing side, which is pretty non-impactful. The majority of a query costs will be the network roundtrip time and the work done in the DB.

    • @AlfredoPinto
      @AlfredoPinto 10 місяців тому

      @@MilanJovanovicTech yes, you are right, you don't say that. But is not about how fast or slow the queries are executed compared to EF and Dapper that makes RepoDB an excellent ORM. What I am saying is that you judge it and discard it without know it, so I got the impression that you do that was just because it wasn't a popular ORM.

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому

      @@AlfredoPinto I researched it a bit in the past, but never ended up using it on a real project. I remember it had some feature limitations. Will check if that's been fixed now.

  • @awesomeaaryan
    @awesomeaaryan Рік тому +1

    Honestly , never been a fan of dapper ... I am glad ef core's performance is improved

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Haven't done the benchmark, but I expect them to be pretty close

  • @harag9
    @harag9 Рік тому

    @12:40 - what an excellent way to get SQL Injection. don't insert parameters like that.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +3

      I see you have no idea how this feature works, or didn't bother hearing my next sentence 😁

    • @harag9
      @harag9 Рік тому

      @@MilanJovanovicTech Correct. I'm still using EF 6 (work hates upgrading). so yea, still new to me. I'm really surprised that this is actually parametised. It just looks so wrong compared to what we do.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      @@harag9 There's FromSqlInterpolated I believe in that version 🤔

  • @gonzalofonsecac
    @gonzalofonsecac Рік тому +1

    No, EF Core sucks for some complex tasks

  • @ahmettarksahin3777
    @ahmettarksahin3777 Рік тому +1

    EF Core to the very last

  • @joek6207
    @joek6207 Рік тому +1

    ADO would have been faster and more clear

  • @mahmudx
    @mahmudx Рік тому

    I'll use dapper until EF Core 8 stable comes out.

  • @techpc5453
    @techpc5453 Рік тому +1

  • @vittoriomorellini1939
    @vittoriomorellini1939 Рік тому +1

    Wonderfull video