Try our conversational search powered by Generative AI!

Can I get all instances of a specific type that has a certain property value using an SDK method?



I know how to grab all the instances of a specifc content type, however I want to only get instances of that content type that have a specific property value;

var value = 11;
var repo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var usage = ServiceLocator.Current.GetInstance<IContentModelUsage>();

var contentType = repo.Load<YourContentType>();
var usages = contentModelUsage.ListContentOfContentType(contentType);

// is there a native EPiServer way of doing the following without having to GetInstance<>() each instance?
var matches = usages.Select(pl => ServiceLocator.Current.GetInstance<YourContentType>(pl)).Where(c => c.SomeProperty == value);


Is there an EPiServer SDK way of doing this so that I do not have to use GetInstance for each of the content items?







Jul 31, 2013 15:19

Hi, Martin,

This is how I did it, too, I don't know any other way. I believe that EPiServer Find is meant to be used in these cases.


Jul 31, 2013 15:42

If you want to load content with a specific property value I would look at using search instead, using search to find out the content id and load it that way.

Jul 31, 2013 15:43

If you don't have EPiServer Find installed, try with a simple FindPagesWithCriteria. Note that FindPagesWithCriteria runs queries directly to the database so I would recommend that you're using Cache on your results.

Jul 31, 2013 15:55
Jul 31, 2013 15:55

Thanks to you all for your replies. Very helpful.

Sadly, EPiFind is not a solution for us because client did not want to use it.

However, we will be using a bespoke SOLR solution for site search. Perhaps it makes sense to add all of the content item properties to the search index rather than just the textual/end-user searchable properties.
Then I can make use of that solution for this purpose.

Aug 01, 2013 11:28

If you only want to depend on internal EPiServer functionality, you still have FindPagesWithCriteria where you can read directly against content EPiServer instead of relying on indexed data in a third party solution

Aug 01, 2013 11:34
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.