AI OnAI Off
What version of Episerver CMS are you using?
Try adding this attribute to your Comment class:
[EPiServerDataStore(AutomaticallyCreateStore = true, AutomaticallyRemapStore = true)]
public class Comment : IDynamicData
{
// Required to implement IDynamicData
public Identity Id { get; set; }
// Save datetime comment was created
public DateTime DateTime { get; set; }
// Save pageID of page on which comment was created.
public int PageID { get; set; }
// Save name of person who commented
public string Name { get; set; }
// Holds the actual comment
public string Text { get; set; }
}
Then
var store = DynamicDataStoreFactory.InstanceGetOrCreateStore(typeof(Comment));
var comment = new Comment();
// Initialize comment, make sure the Id property are set.
store.Save(comment);
Hi Dileep,
As you are using a different class library project so make sure your DB context is initialized properly before you perform any operation.
You can refer an article here-
Thanks
Ravindra S. Rathore
Hello,
I am working on a POC with Dynamic data saving and retrieving and have followed the below article.
https://roland.kierkels.net/2014/10/storing-data-using-episerver-7-5-dynamic-data-store . Howe
I get Object variable not set error while saving a new record on the line .
var store = DynamicDataStoreFactory.Instance.CreateStore(typeof (Comment));
Not sure if I am missing anything in the config file or an initialization module.This is what I have in the config: Can someone point me what am I missing.
Note: I am doing this in a class library so that I can reference it later in web project if we decide on going with DDS.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="episerver.dataStore" type="EPiServer.Data.Configuration.EPiServerDataStoreSection, EPiServer.Data" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EPiServer.Framework" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.13.1.0" newVersion="11.13.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Licensing" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.13.1.0" newVersion="11.13.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Data" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.13.1.0" newVersion="11.13.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<episerver.dataStore>
<dataStore defaultProvider="EPiServerSQLServerDataStoreProvider">
<clear />
<providers>
<add name="EPiServerSQLServerDataStoreProvider" description="SQL Server implementation of Data Store" type="EPiServer.Data.Dynamic.Providers.SqlServerDataStoreProvider, EPiServer.Data" connectionStringName="EPiServerDB" />
</providers>
<cache defaultProvider="nullCacheProvider">
<providers>
<add name="httpCacheProvider" description="Http Cache implementation for DataStore" type="EPiServer.Data.Cache.HttpRuntimeCacheProvider,EPiServer.Data.Cache" />
<add name="nullCacheProvider" description="Null Cache implementation for DataStore" type="EPiServer.Data.Cache.NullCacheProvider,EPiServer.Data" />
</providers>
</cache>
</dataStore>
</episerver.dataStore>
<connectionStrings>
<clear />
<add name="EPiServerDB" connectionString="Server=localhost;Database=dbname; User ID=sa;Password=;Connection Timeout=60;Integrated Security=false;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>