+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Question: DynamicData

Question: DynamicData

4 posts, 0 answered
  1. Agustin
    Agustin avatar
    7 posts
    Registered:
    22 Apr 2013
    11 Nov 2013
    Link to this post
    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.
  2. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    11 Nov 2013 in reply to Agustin
    Link to this post
    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!!
  3. Agustin
    Agustin avatar
    7 posts
    Registered:
    22 Apr 2013
    11 Nov 2013
    Link to this post
    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.

     
  4. Agustin
    Agustin avatar
    7 posts
    Registered:
    22 Apr 2013
    11 Nov 2013
    Link to this post
    As a point of clarification, my assumption that the dynamic content types were/are automatically created by sitefinity  is based on the documentation.

    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/deep-dive/dynamic-data/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.
4 posts, 0 answered