我正在尝试使用Orchard HQL API在两个不同的表之间执行简单连接。问题是其中一个表不是ContentPartTable。这可能吗?
这是常规SQL中的样子:
Select * From ItemPartRecord
Join ItemRecord
On ItemRecord.ItemId = ItemPartRecord.ItemId
Where ItemRecord.Price Between 1000 and 10000
我怎么能这样做呢?
答案 0 :(得分:1)
如果有人想知道如何做到这一点:
//Join the non content part table
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("ExampleNamespace.Data.Models"), new Join("ExampleRecord", "ExampleAlias", ",")));
Action<IHqlExpressionFactory> joinOn = predicate => predicate.EqProperty("valueToJoinOn", "aliasToJoinOn.valueToJoinOn");
query = query.Where(
alias => alias.Named("ExampleAlias"),
joinOn
);