简体   繁体   English

SelectMany()在下面如何工作,它使用什么算法?

[英]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? 我的问题是,使用linq时,如何仍可以将新列表元素标识为原始集合的一部分,或者这仅仅是来自实体框架对象跟踪器的内容?

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. 实体框架会跟踪它检索到的所有对象和集合,因此,当您调用context.SaveChanges() (这就是我认为在uow.Commit()方法中发生的事情)时,它已经知道要检查什么。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM