private QueryModelReference ComputeMemberModelReference(MemberExpression member)
        {
            QueryModelReference modelReference = null;
            var memberExp = member.Expression;

            if (memberExp == null)
            {
                throw new Exception(string.Format(Resources.QueryMemberNotAccessible, member.ToString()));
            }

            if (memberExp.NodeType == ExpressionType.Parameter)
            {
                modelReference = GetModelReferenceForNode(memberExp);
            }
            else if (memberExp.NodeType == ExpressionType.TypeAs)
            {
                var resultType          = memberExp.Type;
                var parameterExpression = (memberExp as UnaryExpression).Operand;

                // Handle result is employee, and get person's property case
                // member expression will be "Param_0 As Person"
                if (parameterExpression.Type.IsSubclassOf(resultType))
                {
                    modelReference = GetModelReferenceForNode(parameterExpression);
                }
                else
                {
                    // member expression will be "Param_0 As Employee"
                    var emdEntityType = QueryContext.Model.FindDeclaredType(resultType.FullName);

                    if (emdEntityType is IEdmStructuredType structuredType)
                    {
                        var property = structuredType.FindProperty(member.Member.Name);
                        modelReference = GetModelReferenceForNode(parameterExpression);
                        modelReference = new PropertyModelReference(modelReference, member.Member.Name, property);
                        return(modelReference);
                    }
                }
            }

            if (modelReference != null)
            {
                modelReference = new PropertyModelReference(modelReference, member.Member.Name);
            }

            return(modelReference);
        }
Example #2
0
        private QueryModelReference ComputeMemberModelReference(MemberExpression member)
        {
            QueryModelReference modelReference = null;
            var memberExp = member.Expression;

            if (memberExp.NodeType == ExpressionType.Parameter)
            {
                modelReference = this.GetModelReferenceForNode(memberExp);
            }
            else if (memberExp.NodeType == ExpressionType.TypeAs)
            {
                var resultType          = memberExp.Type;
                var parameterExpression = (memberExp as UnaryExpression).Operand;

                // Handle result is employee, and get person's property case
                // member expression will be "Param_0 As Person"
                if (parameterExpression.Type.IsSubclassOf(resultType))
                {
                    modelReference = this.GetModelReferenceForNode(parameterExpression);
                }
                else
                {
                    // member expression will be "Param_0 As Employee"
                    var emdEntityType = this.QueryContext.Model.FindDeclaredType(resultType.FullName);

                    var structuredType = emdEntityType as IEdmStructuredType;
                    if (structuredType != null)
                    {
                        var property = structuredType.FindProperty(member.Member.Name);
                        modelReference = this.GetModelReferenceForNode(parameterExpression);
                        modelReference = new PropertyModelReference(member.Member.Name, property, modelReference);
                        return(modelReference);
                    }
                }
            }

            if (modelReference != null)
            {
                modelReference = new PropertyModelReference(
                    modelReference, member.Member.Name);
            }

            return(modelReference);
        }
        private QueryModelReference ComputeMemberModelReference(MemberExpression member)
        {
            QueryModelReference modelReference = null;
            var memberExp = member.Expression;
            if (memberExp.NodeType == ExpressionType.Parameter)
            {
                modelReference = this.GetModelReferenceForNode(memberExp);
            }
            else if (memberExp.NodeType == ExpressionType.TypeAs)
            {
                var resultType = memberExp.Type;
                var parameterExpression = (memberExp as UnaryExpression).Operand;

                // Handle result is employee, and get person's property case
                // member expression will be "Param_0 As Person"
                if (parameterExpression.Type.IsSubclassOf(resultType))
                {
                    modelReference = this.GetModelReferenceForNode(parameterExpression);
                }
                else
                {
                    // member expression will be "Param_0 As Employee"
                    var emdEntityType = this.QueryContext.Model.FindDeclaredType(resultType.FullName);

                    var structuredType = emdEntityType as IEdmStructuredType;
                    if (structuredType != null)
                    {
                        var property = structuredType.FindProperty(member.Member.Name);
                        modelReference = this.GetModelReferenceForNode(parameterExpression);
                        modelReference = new PropertyModelReference(member.Member.Name, property, modelReference);
                        return modelReference;
                    }
                }
            }

            if (modelReference != null)
            {
                modelReference = new PropertyModelReference(
                    modelReference, member.Member.Name);
            }

            return modelReference;
        }