Fluent API and DynamicData
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);
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
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?
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
Please can you explain more about this. Is there any documentations are available?
Thanks
jmr
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
Hi Ivan Dimitrov,
Perfect!!!
your answer saved my time
Thanks
jmr