繁体   English   中英

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

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

所以我没有那么特殊的方法

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();
        }
    }

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

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

希望能帮助到你。

暂无
暂无

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

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