Understand your C# queries! IEnumerable & IQueryable in explained

Sdílet
Vložit
  • čas přidán 22. 12. 2022
  • 🔥 Learn the difference between IEnumerable and IQueryable! It is this EASY!
    🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
    Syncfusion Document Processing Library: syncf.co/3E0oCDw
    Syncfusion ASP.NET Core Components: syncf.co/3roV8aE
    We'll make sure to make a Developer out of you in no time!
    So, what is C#?
    C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# enables developers to build many types of secure and robust applications that run in .NET. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers. This tour provides an overview of the major components of the language in C# 8 and earlier. If you want to explore the language through interactive examples, try the introduction to C# tutorials.
    And what is IEnumerable?
    Exposes an enumerator, which supports a simple iteration over a non-generic collection.
    IEnumerable is the base interface for all non-generic collections that can be enumerated. For the generic version of this interface see System.Collections.Generic.IEnumerable. IEnumerable contains a single method, GetEnumerator, which returns an IEnumerator. IEnumerator provides the ability to iterate through the collection by exposing a Current property and MoveNext and Reset methods.
    And what is IQueryable?
    Provides functionality to evaluate queries against a specific data source wherein the type of the data is not specified.
    The IQueryable interface is intended for implementation by query providers. It is only supposed to be implemented by providers that also implement IQueryable. If the provider does not also implement IQueryable, the standard query operators cannot be used on the provider's data source.
    To learn more, make sure to watch the video, and we promise you that you'll become a C# developer by the end of the course! Have fun!
    #csharp #coding #tutorial #learn #microsoft #net #I
    TAGS
    Tutorials,Tutorial,Programming,Course,Learn,Step by step,guide,development,programmer,video course,video tutorial,learn how to,how to,visual studio,c#,.net,.net core,dotnet,visual studio 2019,core,code,asp,asp net,c sharp,ienumerable,iqueryable,coding,linq,entity framework,entity framework core,csharp,iqueryable vs ienumerable,c# ienumerable vs iqueryable,iqueryable .net core,csharp interview,iqueryable vs ienumerable c#,ienumerable vs iqueryable c#
    tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
    This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
    Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x
    C#: / @tutorialseuc
    Facebook: / tutorialseu-1093802040...
    LinkedIn: / tutorialseu
    Discord: / discord

Komentáře • 52

  • @tutorialsEUC
    @tutorialsEUC  Před rokem +1

    🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg

  • @HikingUtah
    @HikingUtah Před 7 měsíci +29

    IEnumerable is an interface. So in your examples, the IEnumerable also has 0 items--just like IQueryable. It's just an interface that you can use to iterate over the list of items (currently stored in your original List). And you don't get the items until you iterate the collection.

  • @Marfig
    @Marfig Před 9 měsíci +18

    Let's be clear here, the only reason why your example worked was that you decided to split the IEnumerable into two separate queries. Had you used the Where() extension method in the declaration of your enumerable object, and you would also have only returned 2500 customers through the network. In your example, there's actually no advantage in using one over the other. I think you can make a better video explaining the differences between IQueryable and IEnumerable if you focus on its actual benefits: With IQueryable, you can more easily compose queries dynamically based on runtime conditions. And you should avoid examples where you use IQueryable outside your ORM layer, unless you make it clear that doing so is actually not going to allow you to easily replace your ORM in the future.

  • @GuildOfCalamity
    @GuildOfCalamity Před rokem +7

    Nice video! Would like to see more like this.
    For your tutorials I would highly recommend enabling "Display inline type hints" and "Display inline parameter name hints" in your VS options so that your viewers can see what the var types are resolving to.

  • @felixpollan
    @felixpollan Před 7 měsíci +5

    5:18 "... IEnumerable is a real collection, it contains all the data..." is definitely wrong, the data are in the list behind the IEnumerable, the IEnumerable itself could be implemented without having any data underneath, the only limitation is that you can use IEnumerable just to move forward. So this is not a good answer in an interview, trust me!

  • @fibs9456
    @fibs9456 Před rokem +14

    It's a little bit misleading that your example is using an in-memory list. This does not show the true benefit of iqueryable since ienumerable is evaluated lazy as well.

    • @tutorialsEUC
      @tutorialsEUC  Před rokem +1

      Hi, true but that's why I said that the list is only to get any kind of data and best to ignore :)
      Got your point anyway!

    • @fibs9456
      @fibs9456 Před rokem

      @@tutorialsEUC true that. I just was confused at the beginning because often watch this kind of video without audio. Nice video btw.
      Cheers

    • @patsornleuangsupornpong9819
      @patsornleuangsupornpong9819 Před rokem

      @@tutorialsEUCI got the whole point in the video but what do you mean by this? Can you explain a bit more? What is evaluated lazy?

    • @OOpSjm
      @OOpSjm Před rokem

      @@patsornleuangsupornpong9819 look up "lazy loading"

  • @higherpurpose1212
    @higherpurpose1212 Před 4 měsíci

    Man, I wish I knew this 10 years ago! It's an eye opener for me, thank you! I will check all your tutorials and subscribe!

  • @johncassidy3071
    @johncassidy3071 Před 14 dny

    Am IEnumerable is often implemented as a coroutine that just promises to get you another element of you're willing to stick around for it. And if you stick around, you'll get them all.

  • @eugenevv
    @eugenevv Před 11 měsíci

    Thank you for an amazing and easy explanation!

  • @tangomoocow
    @tangomoocow Před měsícem

    Great explanation!

  • @billyarredondopucp
    @billyarredondopucp Před rokem

    Finally, I got it. Thank you so much!

  • @EMWMIKE
    @EMWMIKE Před rokem +2

    the Ienumerable can be better if the sql don't have an index of revenue field. So sometimes it is actually better to do a bigger query and then filter from memory.
    Have happened to me a lot of times and implementing new indexes in big transaction tables in production is not easy. So before filtering sql stuff, do your index homework 😀
    Good video !!

  • @pkmx-um9vb
    @pkmx-um9vb Před 2 měsíci

    Really great explanation ... many thanks!

  • @Fkn1405
    @Fkn1405 Před 2 měsíci

    very well explained! Thank U!

  • @user-ue4if1of5c
    @user-ue4if1of5c Před 9 měsíci

    Great explanation 👌

  • @simonroyjonesuk
    @simonroyjonesuk Před rokem +1

    So helpful. Thanks a lot

  • @fahreddinartuklu2620
    @fahreddinartuklu2620 Před 9 měsíci

    thank you bro i understand it and i think there is no missing part. :)

  • @billymartin6497
    @billymartin6497 Před 4 měsíci

    Would this be good for something like an auto complete, or would it be faster to just get the entire list first?

  • @howto8709
    @howto8709 Před 10 měsíci

    Nice video understood totally.

  • @odeyjoshuasunday998
    @odeyjoshuasunday998 Před 7 měsíci

    beautiful, i enjoyed it...simple differences between the two

  • @8ytan
    @8ytan Před rokem +3

    Some of what you said is only true because you chose a list to back the IEnumerable. An IEnumerable doesn't have to be "real" data, e.g. you can make an IEnumerable that is infinitely large.

  • @TkrZ
    @TkrZ Před rokem +4

    No benchmarks?

  • @jannickbreunis
    @jannickbreunis Před rokem +1

    Hello Jannick! Good video, although I have to search how to retrieve/create a IQuerable with my DataAcces and sql.

  • @tusharparmar7142
    @tusharparmar7142 Před rokem +1

    Thanks for sharing. Good content.

  • @ma-arufburad8826
    @ma-arufburad8826 Před 11 měsíci

    Well explained.

  • @ferenc3460
    @ferenc3460 Před rokem +1

    Great! Now I know the difference but what is the benefit of Ienumerable then? Or when I work with DB should I always use queryable?

    • @tutorialsEUC
      @tutorialsEUC  Před rokem

      The benefit is that IEnumerable is a collection (like a list or an array) and you can iterate over the elements. The queryable is no collection. Benefit is the wrong termination here :)
      Greets!

  • @housamalamour7888
    @housamalamour7888 Před rokem +4

    Fantastic Explanation, very clear and easy to understand. Keep it up man!

  • @KBHASKAR-
    @KBHASKAR- Před 6 měsíci

    Thanks bro for vedios

  • @attilaguba856
    @attilaguba856 Před rokem +2

    Thanks very much! Nice one! So basically it's better to use IQueryable to filter data instead IEnumarble!?

    • @tutorialsEUC
      @tutorialsEUC  Před rokem

      Yes, exactly

    • @ygtandoh
      @ygtandoh Před rokem

      Also once u apply a toList() or toArray() to an iQueryable it becomes an iEnumerable

  • @murtazachaudhary7262
    @murtazachaudhary7262 Před rokem +1

    Very well explained, using it from long time, but donot know the differences 😢

  • @ivanvincent7534
    @ivanvincent7534 Před 4 měsíci

    The in memory List negatively effects the example. Setting this up with EFCore would place IQueryable and IEumerable in the correct context.

  • @khabbazz89
    @khabbazz89 Před rokem +1

    nice work

  • @chellaack1644
    @chellaack1644 Před rokem +1

    Awesome

  • @user-qo7yb2hl3q
    @user-qo7yb2hl3q Před 7 měsíci

    easy explanation!

  • @marcelomilbradt6562
    @marcelomilbradt6562 Před 7 měsíci +1

    This video just wrong; both IQueryable and IEnumerable will only execute the code when you iterate through the collection. Both implementations have the same impact on the database since the code is converted to SQL when using a ORM. Also, how can you claim that ICollection is faster without providing any data or benchmarks?

  • @ieminu1875
    @ieminu1875 Před 8 měsíci +1

    * support comment *

  • @gedwistle1974
    @gedwistle1974 Před 3 měsíci

    What you're saying about IEnumerable being an actual collection with data vs IQueryable not having data, is just WRONG. IEnumerable is just an Interface, IQueryable actually implements IEnumerable! All IQueryable instances are already IEnumerables.

  • @Telee_Pawt
    @Telee_Pawt Před 6 měsíci

    Does anybody actually know what is going on with this stuff? We see heaps of examples everywhere but no informationon how anything actually works. Typical "aah" moment to be dashed again below by opposing views.

  • @Turko77777
    @Turko77777 Před 10 měsíci +1

    IEnumerable is NOT a real collection