开发者

Entity Framework 2.0: Cannot update EntityCollection

开发者 https://www.devze.com 2022-12-27 16:59 出处:网络
Let\'s say we have the \"EntityCollection products\". Then the following doesn\'t work: foreach (var product in products)

Let's say we have the "EntityCollection products".

Then the following doesn't work:

foreach (var product in products)
{
 product.LastUpdate = DateTime.Now();
}

As you can also not index an EntityCollect开发者_StackOverflow中文版ion, how do you modify an entity in en EntityCollection?


Try this, i create a generic method to update EntityCollection. Giv me your feed back.

You juste have to modify your product in your products entity collections. And call my GenericUpdateEntityCollection(YourEntityCollection, YourObjectContext); and there you go


Could you try this?

foreach (var product in products.ToArray())
{
     product.LastUpdate = DateTime.Now();
}

You have to copy elements for enumeration with ToArray(), so you can change products.

0

精彩评论

暂无评论...
验证码 换一张
取 消