'An item cannot be deleted from a fixed size Array of type *[]', says Entity Framework.

.net entity-framework silverlight wcf


To maintain my entities, I use EntityFramework.

My issue is that I get the message "An item cannot be deleted from a fixed size Array of type "CarterShop.Commerce.Entities.ManufacturedItemRequirement[]" while submitting a Silverlight-built entity over a WCF to be peristed.

A manufactured item with an ICollection of manufactured item requirements is what I'm entering. For some reason, Entity Framework complains about the collection when I should be able to just "Add" this to the DbContext as a POCO object and persist it elsewhere.

Has this issue ever arisen before? I'm not really sure what it is whining about. The issue originates inside System. Data:

at System.Data.Objects.Internal.PocoPropertyAccessorStrategy.CollectionRemove(RelatedEnd relatedEnd, Object value)
   at System.Data.Objects.Internal.EntityWrapper`1.CollectionRemove(RelatedEnd relatedEnd, Object value)
   at System.Data.Objects.DataClasses.EntityCollection`1.RemoveFromObjectCache(IEntityWrapper wrappedEntity)
   at System.Data.Objects.ObjectStateManager.DegradePromotedRelationships()
   at System.Data.Objects.DataClasses.RelationshipManager.AddRelatedEntitiesToObjectStateManager(Boolean doAttach)
   at System.Data.Objects.ObjectContext.AddObject(String entitySetName, Object entity)
   at System.Data.Entity.Internal.Linq.InternalSet`1.<>c__DisplayClass5.<Add>b__4()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
   at System.Data.Entity.DbSet`1.Add(TEntity entity)
   at Commerce.Model.Repositories.RepositoryBase`1.Add(T entity) in C:\OclProjects 4.1\CarterShop\CarterShop.Commerce.Model\Repositories\RepositoryBase.cs:line 28
   at CarterShop.Commerce.Services.Implementation.StockItemService.CreateManufacturedItem(ManufacturedItem manufactedItem, Boolean createDefinitionAswell) in C:\OclProjects 4.1\CarterShop\CarterShop.Commerce.Services\Implementation\StockItemService.cs:line 137

essentially what I'm doing

ManufacturedItem item = new ManufacturedItem();
item.ManufacturedItemRequirements.Add(new ManufacturedItemRequirement() { Quantity = 1; DefinitionId = 5 });

// Send to WCF...

Context.ManufacturedItems.Add(item); // Error thrown here.
4/5/2011 8:40:46 PM

Accepted Answer

I was adding the graph shown below:

ManufacturedItem has many ManufacturedItemRequirements.
ManufacturedItemRequirement has a ManufacturedItem.
ManufacturedItemRequirement has a StockItemDefinition.

This led to satisfaction. I neglected to notice one aspect of the graph, which is:

StockItemDefinition has many ManufacturedItemRequirements.

It wouldn't function since I wasn't adding the new ManufacturedItemRequirement to this reference array.

Given that there is an implicit link rather than an explicit relationship, I believe I shouldn't need to express this. In my opinion, it should create NULL for these attributes rather than an empty array. The Add procedure works if I set the child array to NULL.

If I am able to alter the serialization, I'll let you know.

4/6/2011 9:11:32 AM

Popular Answer

Other instances in which you may run across this issue include removing entities that were acquired using the.Include extension techniques

The crucial point is that if the partnership is classified as anICollection<T> then an array will be used by Entity Framework to materialize the relationship. However, you may choose from a wide range of legitimate relationship kinds, such as the following:ISet<T> and IList<T> You may fix the issue by defining your relationships using one of these.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow