Hello, how can i set EntityCollection of my entity

Posts   
 
    
Posts: 18
Joined: 21-Mar-2011
# Posted on: 21-Apr-2011 07:51:09   

Hello, i am using two same entities. First is the entity i make back up file. As i insert new entity - some of its fields is not prefetched, so i call method to get this entity and set some properties.

For example: CfrcManufacturerEntity fetchedEnt = cfrService.GetManufacturerWithDetails(manufacturer.ManufacturerId); manufacturer.User = fetchedEnt.User; it works fine, but when i try to set its property which contains EntityCollection, it throws exeption: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. for IEnumerable<CfrcContactPersonEntity> col = fetchedEnt.CfrcContactPerson.AsEnumerable<CfrcContactPersonEntity>();

           manufacturer.CfrcContactPerson.AddRange(col);

How can i set EntityCollection of this entity.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Apr-2011 09:02:49   

Your question is not clear enoough. So I'm not sure what is going on.

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

But the above error is a known .NET error, which occurs when you add or remove items from any collection inside a loop. (A foreach loop enumerating the same modified collection). Try to use the old for(int i = 0; i<.....) way of looping.

Posts: 18
Joined: 21-Mar-2011
# Posted on: 21-Apr-2011 16:07:38   

Hello, i am using it in auditor. When i insert new entity, all of entity's fetched properties are null, so i have to get them from data base to build report on that entity. I found that i can not set some properties(EntityCollections ), so i asked this question. But now it seems to me that using such method is not the best way. I will think further...

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Apr-2011 21:09:48   

Ok, let us know if you need any more help.

Matt