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

Forums / Sitefinity SDK / Fluent API and DynamicData

Fluent API and DynamicData

7 posts, 0 answered
  1. Garry
    Garry avatar
    52 posts
    Registered:
    04 Nov 2010
    16 Oct 2010
    Link to this post
    OK so I'm able to create a new MetaTable of a custom type, but now how do I use the Fluent API to create new records? All I see in the documentation is how to perform CRUD operations on Child Facades not DynamicData Custom Types.

    Here is the MetaTable I'm creating
    private void CreateComicMetaTable()
            {
                App.WorkWith()
           .DynamicData()
           .Type()
           .CreateNew("SitefinityComic", "ComicWidget.Models")
           .Do(dt => dt.DatabaseInheritance = DatabaseInheritanceType.horizontal)
           .Field()
                .CreateNew("Description", typeof(string))
                .Done()
           .Field()
                .CreateNew("URL", typeof(string))
                .Done()
           .Field()
                .CreateNew("ImageExtension", typeof(string))
                .Done()
           .Field()
                .CreateNew("Prefix", typeof(string))
                .Done()
           .Field()
                .CreateNew("PublishedDay", typeof(string))
                .Done()
            .Field()
                .CreateNew("Name", typeof(string))
                .Done()
           .SaveChanges(true);
            }
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Oct 2010
    Link to this post
    Hi Garry,

    Please take a look at New Event fields forum post. In the BETA 2 there are some limitations in the Fluent API.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    10 Feb 2011
    Link to this post
    I created dynamic Data for Blog using fluent API given below

     fluent
                            .DynamicData()
                            .Type(typeof(Blog))
                            .Field().TryCreateNew("PUser", typeof(string)).Done()
                            .Field().TryCreateNew("UPhotoUrl", typeof(string)).Done().SaveChanges(true);

    its not giving error

    if i try to set value like this 

     Guid gDynamicGuid = Guid.NewGuid();
     Blog parentBlog = fluent.Blogs().Where(b => b.Title == sblogPostTitle).Get().First();    
     fluent
                        .BlogPost()
                        .CreateNew()
                        .Do(bP =>
                         {                
                             bP.Parent = parentBlog;
                             bP.Title = sblogPostTitle + gDynamicGuid;
                             bP.Content = scontent;
                             bP.UrlName = sblogPostTitle + gDynamicGuid;
                             bP.DateCreated = DateTime.UtcNow;
                             bP.PublicationDate = DateTime.UtcNow;
                             bP.SetValue("PUser", UserName);
                             bP.SetValue("UPhotoUrl", UserPhotoUrl);

                         })
                        .Publish()
                        .SaveChanges();

    its show the error : 

    Cannot "SetValue", because Telerik.Sitefinity.Blogs.Model.BlogPost does not contain a public property named "PUser".


    How do i assign value for that?





  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2011
    Link to this post
    Hello Jmr,

    It looks like you are creating the field for Blog, but later you are trying to use the field with BlogPost. You should create the field for Telerik.Sitefinity.Blogs.Model.BlogPost object.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    10 Feb 2011
    Link to this post
    Please can you explain more about this. Is there any documentations are available?

    Thanks
    jmr
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Feb 2011
    Link to this post
    Hi Jmr,

    You are createing a dynamic filed for Blog object not for BlogPost and this is why you are getting the error when you try to set/get some value. The dynamic filed should be created for BlogPost ( in your case).

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    14 Feb 2011
    Link to this post
    Hi Ivan Dimitrov,
    Perfect!!!
    your answer saved my time

    Thanks
    jmr



7 posts, 0 answered