Retrieve single DynamicContent item

Posted by Community Admin on 04-Aug-2018 17:56

Retrieve single DynamicContent item

All Replies

Posted by Community Admin on 13-Oct-2013 00:00

I'm relatively new to working with DynamicContent and I'm wondering how to retrieve a single DynamicContent item when you don't know it's ID, only a FieldValue, Title, for example?  The GetDataItem method expects and ID, so I was trying to use GetDataItems like this:

Type officeLocationType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.OfficeLocations.OfficeLocation");
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
var loc = dynamicModuleManager.GetDataItems(officeLocationType).Where(i => i.GetValue<IList>("Title").Equals("Philadelphia")).FirstOrDefault();

But I am getting this error:
Database mapped field uses different type 'System.String'.
Parameter name: methodCallExpression
Actual value was re-i.FieldValue("Title").

How does one get a single DynamicContent item when you don't know the ID?

Posted by Community Admin on 14-Oct-2013 00:00

Under Administration >> Module Builder 

Select your module.  Then on the right there is a Code Reference link which will get you exactly what you need. Should be something similar to this.

var myFilteredCollection = dynamicModuleManager.GetDataItems(officeLocationType).Where(i => i.GetValue<string>("Title") == "Philadelphia").FirstOrDefault();

Posted by Community Admin on 16-Oct-2013 00:00

Hi,

The sample query from Jonathan is the solution to the case the need to call GetValue<T>("FieldName") is due to the fact that in module builder there is no predefined fields available for each item one module can have Title field, but other module might have "SportID" field instead so its up to the user to enter the names for fields chosen in the module.

Regards,
Stanislav Velikov
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested 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