Take the community feedback survey now.
AI OnAI Off
Take the community feedback survey now.
Hi Johan,
How do you set the Id property of your ContactData objects? If the objects have the same identity, the second one will overwrite the first one when saving to the DDS.
In this example the two ContactData objects have the same identity, so totalCount will be equal to 1:
Identity identity = Identity.NewIdentity(Guid.NewGuid());
ContactData contactData1 = new ContactData
{
Id = identity
// Other properties set
};
ContactData contactData2 = new ContactData
{
Id = identity
// Other properties set
};
ContactDataManager.SaveContactData(contactData1);
ContactDataManager.SaveContactData(contactData2);
int totalCount = ContactDataManager.GetAllContactData().Count;
In this example the two ContactData objects have the different identities, so totalCount will be equal to 2:
Identity identity1 = Identity.NewIdentity(Guid.NewGuid());
Identity identity2 = Identity.NewIdentity(Guid.NewGuid());
ContactData contactData1 = new ContactData
{
Id = identity1
// Other properties set
};
ContactData contactData2 = new ContactData
{
Id = identity2
// Other properties set
};
ContactDataManager.SaveContactData(contactData1);
ContactDataManager.SaveContactData(contactData2);
int totalCount = ContactDataManager.GetAllContactData().Count;
Hopefully, this will help you out :)
Karoline
I´m struggeling with the DynamicDataStore (CMS 6 R2 .NET 4.0) and can´t get it to work properly.
It saves my data alright, but when I save a new post it seems to over write the first one. When I try to open the store it always contains just one post.
Anyone?
This is the class that holds the data:
[EPiServerDataStore(AutomaticallyCreateStore = true)] public class ContactData { public String IP { get; set; } public DateTime CreationDate { get; set; } public String Name { get; set; } public String Email{ get; set; } public String Phone1 { get; set; } public String Phone2 { get; set; } public String Message { get; set; } public EPiServer.Data.Identity Id { get; set; } }// This is the functions for saving and retreiving data
public class ContactDataManager { protected static DynamicDataStore GetDynamicDataStore() { return DynamicDataStoreFactory.Instance.GetStore(typeof(ContactData)) ?? DynamicDataStoreFactory.Instance.CreateStore(typeof(ContactData)); } public static void SaveContactData(ContactData contactDataToSave) { var store = GetDynamicDataStore(); store.Save(contactDataToSave); } public static List<ContactData> GetAllContactData(EPiServer.Data.Identity Id) { var store = GetDynamicDataStore(); var query = from contactData in store.Items<ContactData>() select contactData; return query.ToList(); } }