Understand your C# queries! IEnumerable & IQueryable in explained

Поделиться
HTML-код
  • Опубликовано: 22 дек 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

Комментарии • 52

  • @tutorialsEUC
    @tutorialsEUC  Год назад +1

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

  • @HikingUtah
    @HikingUtah 8 месяцев назад +32

    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 10 месяцев назад +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.

  • @fibs9456
    @fibs9456 Год назад +15

    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  Год назад +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 Год назад

      @@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 Год назад

      @@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 Год назад

      @@patsornleuangsupornpong9819 look up "lazy loading"

  • @felixpollan
    @felixpollan 8 месяцев назад +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!

  • @GuildOfCalamity
    @GuildOfCalamity Год назад +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.

  • @higherpurpose1212
    @higherpurpose1212 5 месяцев назад

    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!

  • @8ytan
    @8ytan Год назад +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.

  • @EMWMIKE
    @EMWMIKE Год назад +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 !!

  • @billymartin6497
    @billymartin6497 5 месяцев назад

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

  • @billyarredondopucp
    @billyarredondopucp Год назад

    Finally, I got it. Thank you so much!

  • @eugenevv
    @eugenevv Год назад

    Thank you for an amazing and easy explanation!

  • @fahreddinartuklu2620
    @fahreddinartuklu2620 10 месяцев назад

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

  • @johncassidy3071
    @johncassidy3071 Месяц назад

    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.

  • @TkrZ
    @TkrZ Год назад +4

    No benchmarks?

  • @murtazachaudhary7262
    @murtazachaudhary7262 Год назад +1

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

  • @jannickbreunis
    @jannickbreunis Год назад +1

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

  • @ferenc3460
    @ferenc3460 Год назад +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  Год назад

      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!

  • @ivanvincent7534
    @ivanvincent7534 5 месяцев назад

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

  • @attilaguba856
    @attilaguba856 Год назад +2

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

    • @tutorialsEUC
      @tutorialsEUC  Год назад

      Yes, exactly

    • @ygtandoh
      @ygtandoh Год назад

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

  • @odeyjoshuasunday998
    @odeyjoshuasunday998 8 месяцев назад

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

  • @simonroyjonesuk
    @simonroyjonesuk Год назад +1

    So helpful. Thanks a lot

  • @pkmx-um9vb
    @pkmx-um9vb 2 месяца назад

    Really great explanation ... many thanks!

  • @Fkn1405
    @Fkn1405 3 месяца назад

    very well explained! Thank U!

  • @howto8709
    @howto8709 11 месяцев назад

    Nice video understood totally.

  • @user-ue4if1of5c
    @user-ue4if1of5c 10 месяцев назад

    Great explanation 👌

  • @tusharparmar7142
    @tusharparmar7142 Год назад +1

    Thanks for sharing. Good content.

  • @tangomoocow
    @tangomoocow Месяц назад

    Great explanation!

  • @ma-arufburad8826
    @ma-arufburad8826 Год назад

    Well explained.

  • @KBHASKAR-
    @KBHASKAR- 7 месяцев назад

    Thanks bro for vedios

  • @housamalamour7888
    @housamalamour7888 Год назад +4

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

  • @khabbazz89
    @khabbazz89 Год назад +1

    nice work

  • @chellaack1644
    @chellaack1644 Год назад +1

    Awesome

  • @user-qo7yb2hl3q
    @user-qo7yb2hl3q 8 месяцев назад

    easy explanation!

  • @marcelomilbradt6562
    @marcelomilbradt6562 8 месяцев назад +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 9 месяцев назад +1

    * support comment *

  • @gedwistle1974
    @gedwistle1974 4 месяца назад

    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 7 месяцев назад

    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 11 месяцев назад +1

    IEnumerable is NOT a real collection