Question: DynamicData

Posted by Community Admin on 04-Aug-2018 20:01

Question: DynamicData

All Replies

Posted by Community Admin on 11-Nov-2013 00:00

Can dynamic data items be created thru the fluent API?

I created a dynamic type:

App
  .WorkWith()
  .DynamicData()
  .Type()
  .CreateNew("SimpleDT", "MyCompany.MyProduct.Sitefinity.Models")
  .Do(t => t.DatabaseInheritance = DatabasesInheritanceType.vertical)
  .Field()
  .TryCreateNew("SimpleTextField", typeof(string))
  .Done()
  .SaveChanges(true);

But I cannot figure out how to create an instance of the type, I thought it would be done thru dynamic content but that does not appear to be the case.

var manager = DynamicModuleManager.GetManager(providerName);    
var simpleDT = TypeResolutionService.ResolveType("MyCompany.MyProduct.Sitefinity.Models.SimpleDT");
var simpleDataItem = manager.CreateDataItem(simpleDT);

simpleDataItem.SetValue("SimpleTextField","MySimpleValue")

manager.SaveChanges();


If anyone can point me to the right content manager to manage the dynamicdata types I would greatly appreciate it.

Posted by Community Admin on 11-Nov-2013 00:00

Are you able to confirm that your Dynamic Module was created through Sitefinity backend?  If it has been create there is code reference on how to create Content Items via the API.  There are certain fields you have to set like  "UrlName" and "PublicationDate".  Additionally try using this below:

simpleDataItem.Status = ContentLifecycleStatus.Master;
simpleDataItem.SetWorkflowStatus(
DynamicModuleManager.Provider.ApplicationName, "Published");
DynamicModuleManager.Lifecycle.Publish(programTypeItem);
DynamicModuleManager.SaveChanges();

Happy Coding!!

Posted by Community Admin on 11-Nov-2013 00:00

Jonathan,

Thank you for the reply. 

I guess my assumption was that if I create a dynamic data type thru the API I didn't have to create an actual assembly with the content item type.  I was expecting Sitefinity to either generate it automatically or perhaps extend the DynamicContent type.

 

Posted by Community Admin on 11-Nov-2013 00:00

As a point of clarification, my assumption that the dynamic content types were/are automatically created by sitefinity  is based on the documentation.

www.sitefinity.com/.../dynamic-types

There is no indication that I have to create the assembly for the content item.... which it may defeat the purpose of a "Dynamic" content type.

This thread is closed