Jump to content

C# - Get Collections containing BaseItem


roaku

Recommended Posts

roaku

I have a scenario where I have a BaseItem and want to find out if it is part of a collection with a given name.

 

After deep diving on the forum, I've come up with something that seems to work:

long[] collectionIds = _libraryManager.GetInternalItemIds(new InternalItemsQuery() {
	ListItemIds = new[] {item.InternalId},
	Name = collectionName
});

if (collectionIds.Count() > 0) {
	//our item is in the collection, so do something about it
}

 

But..I was hoping at least some collection information was stored somewhere directly on BaseItem, but that doesn't seem to be the case.

Am I just missing something?

If I do end up having to query for collection for every item, I'll probably try inverting things and and get the collection's children once and cache that result short term, then check each item against that cache.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...