private Net.Vpc.Upa.Expressions.IdCollectionExpression CreateInCollection(Net.Vpc.Upa.Entity entity, System.Collections.Generic.ICollection <Net.Vpc.Upa.Key> collection) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> pfs = entity.GetPrimaryFields();
     Net.Vpc.Upa.Expressions.Var[] v = new Net.Vpc.Upa.Expressions.Var[(pfs).Count];
     for (int i = 0; i < (pfs).Count; i++)
     {
         v[i] = new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(pfs[i].GetEntity().GetName()), pfs[i].GetName());
     }
     if ((pfs).Count == 1)
     {
         Net.Vpc.Upa.Expressions.IdCollectionExpression inColl = new Net.Vpc.Upa.Expressions.IdCollectionExpression(v[0]);
         //inColl.setClientProperty(DefaultEntity.EXPRESSION_SURELY_EXISTS, true);
         foreach (Net.Vpc.Upa.Key k in collection)
         {
             inColl.Add(new Net.Vpc.Upa.Expressions.Literal(k.GetObject(), pfs[0].GetDataType()));
         }
         return(inColl);
     }
     else
     {
         Net.Vpc.Upa.Expressions.IdCollectionExpression inColl = new Net.Vpc.Upa.Expressions.IdCollectionExpression(v);
         //inColl.setClientProperty(DefaultEntity.EXPRESSION_SURELY_EXISTS, true);
         foreach (Net.Vpc.Upa.Key k in collection)
         {
             Net.Vpc.Upa.Expressions.Literal[] l = new Net.Vpc.Upa.Expressions.Literal[(pfs).Count];
             for (int j = 0; j < (pfs).Count; j++)
             {
                 l[j] = new Net.Vpc.Upa.Expressions.Literal(k.GetObjectAt(j), pfs[j].GetDataType());
             }
             inColl.Add(l);
         }
         return(inColl);
     }
 }
 public override Net.Vpc.Upa.Expressions.Expression Copy()
 {
     Net.Vpc.Upa.Expressions.IdCollectionExpression o = new Net.Vpc.Upa.Expressions.IdCollectionExpression(GetLeft().Copy());
     foreach (Net.Vpc.Upa.Expressions.Expression expression in right)
     {
         o.Add(expression);
     }
     return(o);
 }
 public virtual Net.Vpc.Upa.Expressions.Expression GetTargetCondition(Net.Vpc.Upa.Expressions.Expression sourceCondition, string sourceAlias, string targetAlias)
 {
     Net.Vpc.Upa.Field[]           sourceFields = GetSourceRole().GetFields().ToArray();
     Net.Vpc.Upa.Field[]           targetFields = GetTargetRole().GetFields().ToArray();
     Net.Vpc.Upa.Expressions.Var[] lvar         = new Net.Vpc.Upa.Expressions.Var[sourceFields.Length];
     Net.Vpc.Upa.Expressions.Var[] rvar         = new Net.Vpc.Upa.Expressions.Var[targetFields.Length];
     for (int i = 0; i < lvar.Length; i++)
     {
         lvar[i] = (sourceAlias == null) ? new Net.Vpc.Upa.Expressions.Var(sourceFields[i].GetName()) : new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(sourceAlias), sourceFields[i].GetName());
         rvar[i] = (targetAlias == null) ? new Net.Vpc.Upa.Expressions.Var(targetFields[i].GetName()) : new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(targetAlias), targetFields[i].GetName());
     }
     if (tuningMaxInline > 0)
     {
         try {
             System.Collections.Generic.IList <Net.Vpc.Upa.Record> list = GetSourceRole().GetEntity().CreateQuery(new Net.Vpc.Upa.Expressions.Select().Uplet(lvar, "lvar").Where(sourceCondition)).GetRecordList();
             int j = 0;
             Net.Vpc.Upa.Expressions.IdCollectionExpression inCollection = new Net.Vpc.Upa.Expressions.IdCollectionExpression(rvar);
             foreach (Net.Vpc.Upa.Record r in list)
             {
                 j++;
                 if (j > tuningMaxInline)
                 {
                     return(new Net.Vpc.Upa.Expressions.InSelection(lvar, new Net.Vpc.Upa.Expressions.Select().From(GetSourceRole().GetEntity().GetName()).Uplet(lvar).Where(sourceCondition)));
                 }
                 inCollection.Add(new Net.Vpc.Upa.Expressions.Param(null, r.GetSingleResult <T>()));
             }
             //inCollection.add(new Litteral(rs.getObject(1)));
             return(inCollection);
         } catch (Net.Vpc.Upa.Exceptions.UPAException e) {
             return(new Net.Vpc.Upa.Expressions.InSelection(rvar, new Net.Vpc.Upa.Expressions.Select().From(GetSourceRole().GetEntity().GetName()).Uplet(lvar).Where(sourceCondition)));
         }
     }
     else
     {
         return(new Net.Vpc.Upa.Expressions.InSelection(rvar, new Net.Vpc.Upa.Expressions.Select().From(GetSourceRole().GetEntity().GetName()).Uplet(lvar).Where(sourceCondition)));
     }
 }
 public virtual Net.Vpc.Upa.Expressions.Expression GetSourceCondition(Net.Vpc.Upa.Expressions.Expression targetCondition, string sourceAlias, string targetAlias) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     //Key Rkey=getTargetTable().getKeyForExpression(targetCondition);
     Net.Vpc.Upa.Field[] sourceFields = GetSourceRole().GetFields().ToArray();
     Net.Vpc.Upa.Field[] targetFields = GetTargetRole().GetFields().ToArray();
     if (targetCondition is Net.Vpc.Upa.Expressions.IdExpression)
     {
         Net.Vpc.Upa.Key Rkey = targetRole.GetEntity().GetBuilder().IdToKey(((Net.Vpc.Upa.Expressions.IdExpression)targetCondition).GetId());
         if (sourceFields.Length == 1)
         {
             Net.Vpc.Upa.Expressions.Var lvar = (sourceAlias == null) ? new Net.Vpc.Upa.Expressions.Var(sourceFields[0].GetName()) : new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(sourceAlias), sourceFields[0].GetName());
             return(new Net.Vpc.Upa.Expressions.Equals(lvar, new Net.Vpc.Upa.Expressions.Literal(Rkey == null ? null : Rkey.GetValue()[0], targetFields[0].GetDataType())));
         }
         else
         {
             Net.Vpc.Upa.Expressions.Expression a = null;
             for (int i = 0; i < sourceFields.Length; i++)
             {
                 Net.Vpc.Upa.Expressions.Var        lvar = (sourceAlias == null) ? new Net.Vpc.Upa.Expressions.Var(sourceFields[i].GetName()) : new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(sourceAlias), sourceFields[i].GetName());
                 Net.Vpc.Upa.Expressions.Expression rvar = new Net.Vpc.Upa.Expressions.Literal(Rkey == null ? null : Rkey.GetObjectAt(i), targetFields[i].GetDataType());
                 Net.Vpc.Upa.Expressions.Expression e    = new Net.Vpc.Upa.Expressions.Equals(lvar, rvar);
                 a = a == null ? e : a;
             }
             return(a);
         }
     }
     else if (tuningMaxInline > 0)
     {
         Net.Vpc.Upa.Expressions.Var[] lvar = new Net.Vpc.Upa.Expressions.Var[sourceFields.Length];
         Net.Vpc.Upa.Expressions.Var[] rvar = new Net.Vpc.Upa.Expressions.Var[targetFields.Length];
         for (int i = 0; i < lvar.Length; i++)
         {
             lvar[i] = new Net.Vpc.Upa.Expressions.Var((sourceAlias == null) ? null : new Net.Vpc.Upa.Expressions.Var(sourceAlias), sourceFields[i].GetName());
             rvar[i] = new Net.Vpc.Upa.Expressions.Var((targetAlias == null) ? null : new Net.Vpc.Upa.Expressions.Var(targetAlias), targetFields[i].GetName());
         }
         try {
             System.Collections.Generic.IList <Net.Vpc.Upa.Record> list = GetTargetRole().GetEntity().CreateQuery(new Net.Vpc.Upa.Expressions.Select().Uplet(rvar, "rval").Where(targetCondition)).GetRecordList();
             int j = 0;
             Net.Vpc.Upa.Expressions.IdCollectionExpression inCollection = new Net.Vpc.Upa.Expressions.IdCollectionExpression(lvar);
             foreach (Net.Vpc.Upa.Record r in list)
             {
                 j++;
                 if (j > tuningMaxInline)
                 {
                     return(new Net.Vpc.Upa.Expressions.InSelection(lvar, new Net.Vpc.Upa.Expressions.Select().From(GetTargetRole().GetEntity().GetName()).Uplet(rvar).Where(targetCondition)));
                 }
                 inCollection.Add(new Net.Vpc.Upa.Expressions.Param(null, r.GetSingleResult <T>()));
             }
             //inCollection.add(new Litteral(rs.getObject(1)));
             return(inCollection);
         } catch (Net.Vpc.Upa.Exceptions.UPAException e) {
             return(new Net.Vpc.Upa.Expressions.InSelection(lvar, new Net.Vpc.Upa.Expressions.Select().From(GetTargetRole().GetEntity().GetName()).Uplet(rvar).Where(targetCondition)));
         }
     }
     else
     {
         Net.Vpc.Upa.Expressions.Var[] lvar = new Net.Vpc.Upa.Expressions.Var[sourceFields.Length];
         Net.Vpc.Upa.Expressions.Var[] rvar = new Net.Vpc.Upa.Expressions.Var[targetFields.Length];
         for (int i = 0; i < lvar.Length; i++)
         {
             lvar[i] = new Net.Vpc.Upa.Expressions.Var((sourceAlias == null) ? null : new Net.Vpc.Upa.Expressions.Var(sourceAlias), sourceFields[i].GetName());
             rvar[i] = new Net.Vpc.Upa.Expressions.Var((targetAlias == null) ? null : new Net.Vpc.Upa.Expressions.Var(targetAlias), targetFields[i].GetName());
         }
         return(new Net.Vpc.Upa.Expressions.InSelection(lvar, new Net.Vpc.Upa.Expressions.Select().From(GetTargetRole().GetEntity().GetName()).Uplet(rvar).Where(targetCondition)));
     }
 }