public SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { string entityName = criteriaQuery.GetEntityName(criteria, propertyName); string actualPropertyName = criteriaQuery.GetPropertyName(propertyName); string sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName); ISessionFactoryImplementor factory = criteriaQuery.Factory; IQueryableCollection collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory); string[] collectionKeys = collectionPersister.KeyColumnNames; string[] ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames; StringBuilder innerSelect = new StringBuilder(); innerSelect.Append("(select 1 from ") .Append(collectionPersister.TableName) .Append(" where ") .Append( new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment()); if (collectionPersister.HasWhere) { innerSelect.Append(" and (") .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName)) .Append(") "); } innerSelect.Append(")"); return(new SqlString(new string[] { ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString() })); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { string entityName = criteriaQuery.GetEntityName(criteria, propertyName); string actualPropertyName = criteriaQuery.GetPropertyName(propertyName); string sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName); ISessionFactoryImplementor factory = criteriaQuery.Factory; IQueryableCollection collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory); string[] collectionKeys = collectionPersister.KeyColumnNames; string[] ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames; StringBuilder innerSelect = new StringBuilder(); innerSelect.Append("(select 1 from ") .Append(collectionPersister.TableName) .Append(" where ") .Append( new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment()); if (collectionPersister.HasWhere) { innerSelect.Append(" and (") .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName)) .Append(") "); } innerSelect.Append(")"); return new SqlString(new string[] {ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString()}); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { var entityName = criteriaQuery.GetEntityName(criteria, propertyName); var actualPropertyName = criteriaQuery.GetPropertyName(propertyName); var sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName); var factory = criteriaQuery.Factory; var collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory); var collectionKeys = collectionPersister.KeyColumnNames; var ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames; var innerSelect = new StringBuilder(); innerSelect.Append("(select 1 from ") .Append(collectionPersister.TableName) .Append(" where ") .Append( new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment()); if (collectionPersister.HasWhere) { innerSelect.Append(" and (") .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName)) .Append(") "); } innerSelect.Append(")"); return(new SqlString(new object[] { ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString() })); }