簡體   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