开发者

Entity Framework 2.0: Cannot update EntityCollection

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜