Querying and filtering (Where()) content part without the record

Topics: Writing modules
Developer
Sep 27, 2011 at 9:10 PM

Hi all!

Is there a way to query (with content manager perhaps) for a content part, without specifying the used record? For example the ContentManager's Get() is working without having to add a record type parameter, but Where() isn't. As far as I know since Orchard is storing the connection between a part(record) and a record (and the record type is also stored in ContentPart), this should be possible. So why is _contentManager.Query<MyPart>().Where(part => part.Id < 5); not possible?

Coordinator
Sep 27, 2011 at 9:18 PM

That's because the content manager actually has no way of knowing how a part stores its contents. It might come from a web service, from a different database, who knows?

Developer
Sep 27, 2011 at 9:47 PM

This sounds very reasonable, but how does then Get() knows? (As far as I understand a ContentItem is aware of its parts.) Just curious :-). And a content part that is derived from ContentPart<TRecord> contains a reference to its record (so we know how it is stored). Maybe it would be possible to query only content part that inherit from the generic ContentPart?

Coordinator
Sep 27, 2011 at 10:19 PM

Get takes a content item id. Content items always have a record. Once you have the content item, you can As it into its parts, which is when the part is responsible for fetching its own data.

Developer
Sep 29, 2011 at 9:05 AM

Thanks, this cleared things up.