How does SelectMany() work underneath, what algorithm does it use?

So i have this not so special method

public void FlagVoyageAsRemoved(int voyageId)
    {
        using (UnitOfWork uw = new UnitOfWork())
        {
            Voyage voyage = uw.VoyageRepository.FindSingle(v => v.VoyageId == voyageId,  
new string[] { "VoyageUsers.Costs" });
            List<Cost> userCosts = voyage.VoyageUsers.SelectMany(vu => vu.Costs).ToList();
//altough i am putting my items in a new list meaning its a new memory adress, the object tracker can still see them as part of the original collection, how come?
            costBl.FlagCostsAsDeleted(userCosts);
// these methods just change a proprety in each element of the collection, nothing more.
            costBl.FlagCostsAsDeleted(voyage.Costs);
            vUserBl.FlagVoyageUsersAsDeleted(voyage.VoyageUsers);
            voyage.HasDeleteFlag = true;
            uw.Commit();
        }
    }

My question is how do the new list elements can still be identified as part of the original collection, when using linq, or is this just something coming from the entity framework object tracker?

Answers


Entity Framework keeps track of all the objects and collections it retrieves, so when you call context.SaveChanges() (and that is what I think is happening in your uow.Commit()method) it already know what to check.

Hope it helps.


Need Your Help

Clearing the terminal screen?

terminal refresh arduino clear erase

I'm reading data from 9 different sensors for my robot and I need to display them all steadily, in the same window so I can compare the values and see if any of the readings is off.

How to create “hovering” buttons in Silverlight?

silverlight

I saw a Silverlight effect the other that I quite liked, and I was wondering how to reproduce it. The main screen of the app had 5 or 6 large buttons that were gently moving up and down a few pixel...