LINQ - Removing elements in source list prevents enumeration of "c

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VG9kZCBCZWF1bGlldQ==?=

    #1

    LINQ - Removing elements in source list prevents enumeration of "c

    Hello, I have a list of elements and I want to perform an operation on a
    subset of them and then remove them from the list.

    If I build a sequence of elements via LINQ to drive the enumeration, as soon
    as I remove the first element the enumeration operation is broken.

    This surprises me. I thought the LINQ'd sequence would be its own
    collection, impervious to changes in the original source collection.
  • =?Utf-8?B?VG9kZCBCZWF1bGlldQ==?=

    #2
    Re: LINQ - Removing elements in source list prevents enumeration o

    Jon, do you need a place to live? We'll provide food, shelter and beer, in
    exchange for a brain tap.

    Thank you.

    "Jon Skeet [C# MVP]" wrote:
    No - LINQ streams the data (when it can), so it will still be asking
    the original data source for data as it goes.
    >

    Comment

    • Frans Bouma [C# MVP]

      #3
      Re: LINQ - Removing elements in source list prevents enumeration of "c

      Jon Skeet [C# MVP] wrote:
      Todd Beaulieu <ToddBeaulieu@d iscussions.micr osoft.comwrote:
      Hello, I have a list of elements and I want to perform an operation
      on a subset of them and then remove them from the list.
      >
      If I build a sequence of elements via LINQ to drive the
      enumeration, as soon as I remove the first element the enumeration
      operation is broken.

      This surprises me. I thought the LINQ'd sequence would be its own
      collection, impervious to changes in the original source collection.
      >
      No - LINQ streams the data (when it can), so it will still be asking
      the original data source for data as it goes.
      Only outside a db. Any linq-access to a db isn't streamed but batched
      (i.e.: fetch everything to the client)

      FB

      --
      ------------------------------------------------------------------------
      Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
      LLBLGen Pro website: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ------------------------------------------------------------------------

      Comment

      Working...