Ejemplo n.º 1
0
        public virtual Net.Vpc.Upa.Expressions.Expression CreateFindEntityByMainPathExpression(string mainFieldPath, string entityAlias)
        {
            Net.Vpc.Upa.Entity           entity     = GetEntity();
            Net.Vpc.Upa.RelationshipRole detailRole = GetTreeRelationship().GetSourceRole();
            if (Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(mainFieldPath))
            {
                return(null);
            }
            string mainFieldName  = entity.GetMainField().GetName();
            object mainFieldValue = null;
            object parent         = null;

            string[] parentAndName = Net.Vpc.Upa.Impl.Util.StringUtils.Split(mainFieldPath, GetHierarchyPathSeparator()[0], false);
            if (parentAndName != null)
            {
                parent         = FindEntityByMainPath(parentAndName[0]);
                mainFieldValue = parentAndName[1];
            }
            else
            {
                mainFieldValue = mainFieldPath;
            }
            Net.Vpc.Upa.Expressions.Expression expr = null;
            if (entityAlias == null)
            {
                entityAlias = entity.GetName();
            }
            expr = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entityAlias), mainFieldName), mainFieldValue);
            Net.Vpc.Upa.Key entityToKey = parent == null ? null : entity.GetBuilder().ObjectToKey(parent);
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = detailRole.GetFields();
            for (int index = 0; index < (primaryFields).Count; index++)
            {
                Net.Vpc.Upa.Field field = primaryFields[index];
                expr = new Net.Vpc.Upa.Expressions.And(expr, new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(new Net.Vpc.Upa.Expressions.Var(entityAlias), field.GetName()), entityToKey == null ? null : entityToKey.GetObjectAt(index)));
            }
            return(expr);
        }