0

所以我有这个不那么特别的方法

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 时,新的列表元素如何仍然可以被识别为原始集合的一部分,或者这只是来自实体框架对象跟踪器的东西?

4

1 回答 1

1

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

希望能帮助到你。

于 2012-09-08T21:13:23.077 回答