Question

I'm trying to join a JobPart to both a TitlePartRecord and a BodyPartRecord, and perform a logical OR for text contained in either the Title or Body parts.

My first attempt was to use the ContentManager to Join the parts, however, I cannot perform an OR, only an AND, as a WHERE clause is only applied to the Join immediately above:

        var q = _orchardServices.ContentManager.Query<JobPart>()
                .Join<TitlePartRecord>()
                .Where(r => r.Title.Contains(filter.FreeText))
                .Join<BodyPartRecord>()
                .Where(r => r.Text.Contains(filter.FreeText))
                .List();

So the above will return JobParts where the search term is in both the Body and Title parts, just not in either.

My next attempt was to use the HqlQuery, where someone is having the same issue described here:

        var q = _orchardServices.ContentManager.HqlQuery()
                .ForPart<JobPart>()
                .Join(x => x.ContentPartRecord<TitlePartRecord>())
                .Join(x => x.ContentPartRecord<BodyPartRecord>())
                .Where(alias => alias.ContentPartRecord<TitlePartRecord>(),
                        factory => factory.Or(
                            lhs => lhs.InsensitiveLike("Title", filter.FreeText, HqlMatchMode.Anywhere),
                            rhs => rhs.InsensitiveLike("Text", filter.FreeText, HqlMatchMode.Anywhere)));

However, this fails as the OR is being applied to the TitlePart, and "Text" is not a property of the TitlePart, rather the BodyPart.

Can anyone point me in the correct direction to perform an OR across the join? Sure I'm missing something small.

Thank you

Was it helpful?

Solution

No - this is not possible with "OR", only "AND"....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top