DynamicData

Posted by Community Admin on 03-Aug-2018 18:00

DynamicData

All Replies

Posted by Community Admin on 03-Dec-2010 00:00

I've seen information about how to define new meta data for DynamicData.


However, I cannot seem to find any simple examples of adding new records into the table, finding specific records, or deleting those records.

Is there a existing API where I can perform these tasks programmatically? Are there any examples somewhere? (Please don't refer me to some automagical telerik binding control--I'm interested in an API that I can program against, if it exists.)

Thank you.

Posted by Community Admin on 06-Dec-2010 00:00

I've been searching for this a while too. And have come to the conclusion that it's not ready yet.


You can add custom field to existing types (NewsItem, Content, etc) and update them, as shown in Jobs module; but cannot add completely new types.

I think the closest solution right now is to create a new object similar to built-in objects (refer to Sitefinity source code), but that involves creating a series of abstraction classes and OpenAccess configurations/data providers. But that is going to take quite a bit of effort to get it working, and probably not worth it, especially if the FluentAPI is going to be completed with methods for dynamic data later which has been hinted a couple times.

Posted by Community Admin on 06-Dec-2010 00:00

Hi,

1. You can create a new property for a given type by using  TryCreateNew - tries to create a new instance of the "MetaField" with the specified field name and type. Field will be created only if the field with such name does not exist. So this create a dynamic property for your field.

2. You can create a new type which is more complicated, because currently there is no a common facade or manager that will allow you to use your custom type directly and you have to use a custom manager and WCF RESTful service to update the data for your custom type. We are working on a common facade that will be included in one of the next internal builds and will allow you manage each content type that inherits from Content.

There is an extension method - SetValue which is used to set a value to the custom field - sets the value of a dynamic property of data item to a different value.

Here are several samples that shows how to create, update or delete a property value

1. Create a new property

App.WorkWith().DynamicData().Type(typeof(NewsItem)).Field().CreateNew("somevalue", typeof(string)).SaveChanges();

2. Update the property
          
var itm = App.WorkWith().NewsItems().Where(ni => ni.Title == "test").Get().SingleOrDefault();
itm.SetValue("somevalue", "val");

3. Delete the property from the type.

App.WorkWith().DynamicData().Fields().Where(dc => dc.FieldName == "test").Delete();

DynamicFieldFacade has two facade method that you can use

public DynamicFieldFacade Field(Guid dynamicFieldId)
public DynamicFieldFacade Field(MetaField dynamicField)



Kind regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed