Adding an entity to a collection using Adapter?

Posts   
 
    
Posts: 1
Joined: 05-Feb-2010
# Posted on: 05-Feb-2010 15:07:16   

I've always used the SelfServicing templates and recently decided to give Adapter a try, since we're using more and more WCF/WebServices.

One of the simple things I used to do in SelfServicing is add new entities to a collection by using the entity.relatedCollection.Add method. In adapter this gives me a 'Collection is read-only' error. I was wondering why this behaviour isn't possible using the adapter classes?

Example:


            var collection = new CollectionEntity(1);
            var prefetch = new PrefetchPath2(EntityType.CollectionEntity);
            prefetch.Add(CollectionEntity.PrefetchPathAssets);
            
            adapter.FetchEntity(collection, prefetch);
            
            collection.Assets.AddNew();
            adapter.SaveEntity(collection);

Should I manually set the parent ID on a new Entity or create a link-table entity to add an entity to a related collection?

I'm using 2.6 on .NET 3.5.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Feb-2010 03:33:22   

Is collection.Assets a m:n relation? If that is the case, you should add it in a special way (See the last example on this link).

David Elizondo | LLBLGen Support Team