internal override JoinFragment ToJoinFragment( IDictionary <string, IFilter> enabledFilters, bool includeExtraJoins, SqlString withClauseFragment, string withClauseJoinAlias, string withRootAlias) { var joinFragment = new ANSIJoinFragment(); var on = withClauseFragment ?? SqlString.Empty; //Note: filters logic commented due to following issues //1) Original code is non functional as SqlString is immutable and so all Append results are lost. Correct code would look like: on = on.Append(filters); //2) Also it seems GetOnCondition always returns empty string for entity join (as IsReferenceToPrimaryKey is always true). // So if filters for entity join really make sense we need to inline GetOnCondition part that retrieves filters // var filters = _entityType.GetOnCondition(_tableAlias, Factory, enabledFilters); // if (!string.IsNullOrEmpty(filters)) // { // on.Append(" and ").Append(filters); // } joinFragment.AddJoin(_tableName, _tableAlias, Array.Empty <string>(), Array.Empty <string>(), _joinType, on); if (includeExtraJoins) { AddExtraJoins(joinFragment, _tableAlias, _entityType.GetAssociatedJoinable(Factory), _joinType == JoinType.InnerJoin); } return(joinFragment); }
private bool ProcessAsTableGroupJoin(bool includeAllSubclassJoins, SqlString[] withClauseFragments, JoinFragment joinFragment) { if (!NeedsTableGroupJoin(joins, withClauseFragments, includeAllSubclassJoins)) { return(false); } var first = joins[0]; string joinString = ANSIJoinFragment.GetJoinString(first.JoinType); joinFragment.AddFromFragmentString( new SqlString( joinString, " (", first.Joinable.TableName, " ", first.Alias )); foreach (var join in joins) { if (join != first) { joinFragment.AddJoin( join.Joinable.TableName, join.Alias, join.LHSColumns, JoinHelper.GetRHSColumnNames(join.AssociationType, factory), join.JoinType, SqlString.Empty); } AddSubclassJoins( joinFragment, join.Alias, join.Joinable, // TODO (from hibernate): Think about if this could be made always true // NH Specific: made always true (original check: join.JoinType == JoinType.InnerJoin) true, includeAllSubclassJoins ); } var tableGroupWithClause = GetTableGroupJoinWithClause(withClauseFragments, first); joinFragment.AddFromFragmentString(tableGroupWithClause); return(true); }
internal static bool ProcessAsTableGroupJoin(IReadOnlyList <IJoin> tableGroupJoinables, SqlString[] withClauseFragments, bool includeAllSubclassJoins, JoinFragment joinFragment, Func <string, bool> isSubclassIncluded, ISessionFactoryImplementor sessionFactoryImplementor) { if (!NeedsTableGroupJoin(tableGroupJoinables, withClauseFragments, includeAllSubclassJoins)) { return(false); } var first = tableGroupJoinables[0]; string joinString = ANSIJoinFragment.GetJoinString(first.JoinType); joinFragment.AddFromFragmentString( new SqlString( joinString, " (", first.Joinable.TableName, " ", first.Alias )); foreach (var join in tableGroupJoinables) { if (join != first) { joinFragment.AddJoin( join.Joinable.TableName, join.Alias, join.LHSColumns, JoinHelper.GetRHSColumnNames(join.AssociationType, sessionFactoryImplementor), join.JoinType, SqlString.Empty); } bool include = includeAllSubclassJoins && isSubclassIncluded(join.Alias); // TODO (from hibernate): Think about if this could be made always true // NH Specific: made always true (original check: join.JoinType == JoinType.InnerJoin) const bool innerJoin = true; joinFragment.AddJoins( join.Joinable.FromJoinFragment(join.Alias, innerJoin, include), join.Joinable.WhereJoinFragment(join.Alias, innerJoin, include)); } var withClause = GetTableGroupJoinWithClause(withClauseFragments, first, sessionFactoryImplementor); joinFragment.AddFromFragmentString(withClause); return(true); }
internal override JoinFragment ToJoinFragment( IDictionary <string, IFilter> enabledFilters, bool includeExtraJoins, SqlString withClauseFragment, string withClauseJoinAlias, string withRootAlias) { var joinFragment = new ANSIJoinFragment(); var on = withClauseFragment ?? new SqlString(); var filters = _entityType.GetOnCondition(_tableAlias, Factory, enabledFilters); if (!string.IsNullOrEmpty(filters)) { on.Append(" and ").Append(filters); } joinFragment.AddJoin(_tableName, _tableAlias, Array.Empty <string>(), Array.Empty <string>(), _joinType, on); return(joinFragment); }