HqlQuery join with custom table

Topics: Writing modules, Русский (Russian)
Feb 19, 2013 at 10:14 PM
Edited Feb 19, 2013 at 10:15 PM
How can i get sql query by HqlQuery like
...
join Contrib_Voting_VoteRecord as vr on vr.ContentItemRecord_id = Orchard_Framework_ContentItemRecord.Id
...
where vr.Value > 2
Contrib_Voting_VoteRecord is non Content Part Table. It is custom table from Contrib.Voting module
Feb 24, 2013 at 6:43 PM
working example:
            var query = (IHqlQuery)context.Query;
            query.Join(alias => alias.ContentItem());
            var defaultHqlQuery = query as DefaultHqlQuery;
            var fiJoins = typeof(DefaultHqlQuery).GetField("_joins", BindingFlags.Instance | BindingFlags.NonPublic);
            var joins = fiJoins.GetValue(defaultHqlQuery) as List<Tuple<IAlias, Join>>;
            joins.Add(new Tuple<IAlias, Join>(new Alias("Contrib.Voting.Models"), new Join("VoteRecord", "vote", ",")));
            query.Where(
                alias => alias.Named("vote"),
                predicate => predicate.EqProperty("ContentItemRecord", "ci"));