Try our conversational search powered by Generative AI!

Generic collection in Dynamic Data Store



I'm trying to store a generic collection in the dynamic data store but fails to do that. I have created a Comment class consisting of three string properties and a Comments class which is a generic collection (List) of data type Comment.

First I have created a pageobjectmanager:
pom = new PageObjectManager(CurrentPage);

In the page OnLoad event handler I do this:
comments = pom.Load<Comments>("comments");

When I store the values I do this:
pom.Save("comments", comments);

Even though the comments list has a comment when I store the value, after reloading the page its value is gone. Does anyone have a clue why this happens or do you perhaps know of any other way to store a collection in the DDS?

Apr 20, 2010 8:16

I do exactly what you are trying to accomplish.

Remeber to use the Identity from the IDynamicDatainterface on the objects.

someobject.ID = Identity.NewIdentity(Guid.NewGuid());


Apr 20, 2010 8:38

Thanks for your reply Morten,

unfortunately I still don't understand what I have to do to make it work, could you please try to explain it more thoroughly?

Many thanks in advance!

Apr 20, 2010 13:15

I had something like this happen too.  When I reloaded the page, PageObjectManager had a record of the key, but the value was always NULL.

Is this what's happening to you too?  I have no solution, sadly.

Apr 20, 2010 15:13

Hi Deane,

that is exactly what happens to me. Anyone who has a solution to this?

Apr 20, 2010 15:30


I have it partially figured out --

In the class that you're storing, you have to implement IDynamicData.  When you do this, you just have to add this to your class:

public EPiServer.Data.Identity Id { get; set; }

I did this with a custom class, and it worked perfectly.

(My problem, however, is -- how do you store a primitive?  I just want to store an int.  Since I can't implement an interface on a primitive, is it impossible to store a primitive?)


Apr 21, 2010 6:46

DDS takes the approach to save an object by saving all its properties, and by default it
saves all "simple" (non-indexed) properties (not fields) that are public and has a getter and a setter.

When you pass in a List<T>, the only property that fullfills this is the Capacity property,
and the actual items in the list wont get saved.

You would need to wrap the List<T> in your own class, and then pass it to DDS save(),
something like this:

public class CommentsWrap
   public List<Comment> Comments { get; sst; }


Edited, Apr 21, 2010 10:16

Here is how I've done it:


   public class TheList : IDynamicData
        #region IDynamicData Members

        public Identity Id { get; set; }

        public List<TheItem> Items { get; set; }

    public class TheItem : IDynamicData
        public string MyString { get; set; }
        public int MyItn { get; set; }

        #region IDynamicData Members
        public Identity Id { get; set; }



Apr 21, 2010 10:24

Thanks all for your answers!

I don't have time to test this right now but as Morten already has a working solution I'm pretty sure this will solve my problem and therefore I will mark this thread as answered.

Thanks once again!

Apr 21, 2010 10:38


So, can you store primitives in DDS?  Like an int?  Or would have to wrap my int in a custom class that implements IDynamicData and exposes the int as a public property?


Apr 21, 2010 14:20

No, you for the same reason as for the List<T> case, you cannot store primitives directly in DDS.

You need to encapsulate it into a type, and expose it through a property like so:

public class MyClass
   public int MyInt { get; set; }


Apr 21, 2010 14:22

Content removed since I was spreading lies with regards to primitives ;-)

Edited, Apr 21, 2010 14:26

There's actually a second limitation in play here. You can't store generics - at least not as a PageObjects or in "typed" stores - since their generated store names include forbidden characters.

Apr 22, 2010 8:15

Not sure what you mean here Magnus,

The code I posed a few post up, with a Genering list of another class works perfect.
I might be missing your point here though :-)


Apr 22, 2010 8:26

Yeah, you're storing objects of a class called TheList. You couldn't store your List<TheClass> directly because it lacks public properties. But you could not even store a TheList<T> if you wanted that for some reason (for example to create a generic metaclass for lists which has a property storing the actual list just like in your example). This doesn't stop at lists or list-like objects of course, it applies to all generic classes.

Apr 22, 2010 8:31

Ah that's what you meant :-)


Apr 22, 2010 8:34
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.