Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
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());
Regards,
Morten
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!
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.
Hi Deane,
that is exactly what happens to me. Anyone who has a solution to this?
Jens:
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?)
Deane
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; }
}
Regards,
Johan
Here is how I've done it:
public class TheList : IDynamicData public Identity Id { get; set; } #endregion public class TheItem : IDynamicData #region IDynamicData Members Regards,
{
#region IDynamicData Members
public List<TheItem> Items { get; set; }
}
{
public string MyString { get; set; }
public int MyItn { get; set; }
public Identity Id { get; set; }
}
Morten
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!
All:
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?
Deane
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; }
}
/johan
Content removed since I was spreading lies with regards to primitives ;-)
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.
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 :-)
//Morten
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.
Hi,
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?