///
 public PXDBAttributeAttribute(Type valueSearch, Type attributeID)
 {
     if (valueSearch == null)
     {
         throw new PXArgumentException("type", ErrorMessages.ArgumentNullException);
     }
     if (attributeID == null)
     {
         throw new PXArgumentException("field", ErrorMessages.ArgumentNullException);
     }
     _Field = attributeID;
     if (typeof(IBqlSearch).IsAssignableFrom(valueSearch))
     {
         _SingleSelect = BqlCommand.CreateInstance(valueSearch);
     }
     else if (valueSearch.IsNested && typeof(IBqlField).IsAssignableFrom(valueSearch))
     {
         _SingleSelect = BqlCommand.CreateInstance(typeof(Search <>), valueSearch);
     }
     else
     {
         throw new PXArgumentException("valueSearch", ErrorMessages.CantCreateForeignKeyReference, valueSearch);
     }
     _PureWhere    = (_SingleSelect as IHasBqlWhere).GetWhere();
     _SubSelect    = _SingleSelect.WhereAnd(typeof(Where <,>).MakeGenericType(_Field, typeof(Equal <AttributeIDPlaceholder>)));
     _SingleSelect = _SingleSelect.WhereAnd(BqlCommand.Compose(typeof(Where <,>), _Field, typeof(Equal <>), typeof(Required <>), _Field));
 }
        protected SQLTree.Query GetAttributesJoinedQuery(PXGraph graph, StringBuilder text, List <Type> types, Type fieldWithValue, IBqlWhere _PureWhere)
        {
            Type table0 = BqlCommand.GetItemType(fieldWithValue);
            Type table  = BqlCommand.FindRealTableForType(types, table0);

            SQLTree.SQLExpression exp = null;
            _PureWhere.AppendExpression(ref exp, graph, new BqlCommandInfo(false)
            {
                Tables = types
            }, null);

            return(new SQLTree.JoinedAttrQuery(table.Name, fieldWithValue.Name, "AttributeID", "RefNoteID", exp));
        }