Example #1
0
        protected override Expression VisitMember(MemberExpression expression)
        {
            ModelMetadataRepository modelMetadataRepository = new ModelMetadataRepository();

            EntityModelType entityModel = modelMetadataRepository.GetModelMetadata(expression.Member.DeclaringType);

            if (entityModel != null)
            {
                var crmAttributeLogicalName = entityModel.ParameterToAttributeLogicalName[expression.Member.Name];

                var entityLogicalName = entityModel.EntityLogicalName;
                if (!EntityAttributes.ContainsKey(entityLogicalName))
                {
                    EntityAttributes.Add(entityLogicalName, new List <string>());
                }
                EntityAttributes[entityLogicalName].Add(crmAttributeLogicalName);
            }
            else
            {
                var entityLogicalName = processingEntity.Peek();
                if (!EntityAttributes.ContainsKey(entityLogicalName))
                {
                    EntityAttributes.Add(entityLogicalName, new List <string>());
                }
                EntityAttributes[entityLogicalName].Add(expression.Member.Name);
            }


            return(expression);
        }
        protected override Expression VisitConstant(ConstantExpression expression)
        {
            ModelMetadataRepository modelMetadataRepository = new ModelMetadataRepository();

            EntityModelType entityModel = modelMetadataRepository.GetModelMetadata(expression.Type);

            if (entityModel != null)
            {
                var crmAttributeLogicalName = entityModel.ParameterToAttributeLogicalName[(string)expression.Value];


                _actualFetchXml.Append(crmAttributeLogicalName);
            }
            else
            {
                _actualFetchXml.Append(expression.Value);
            }

            return(expression);
        }
        protected override Expression VisitMember(MemberExpression expression)
        {
            ModelMetadataRepository modelMetadataRepository = new ModelMetadataRepository();

            EntityModelType entityModel = modelMetadataRepository.GetModelMetadata(expression.Member.DeclaringType);

            if (entityModel != null)
            {
                var crmAttributeLogicalName = entityModel.ParameterToAttributeLogicalName[expression.Member.Name];


                _actualFetchXml.Append(crmAttributeLogicalName);
            }
            else
            {
                _actualFetchXml.Append(expression.Member.Name);
            }

            return(expression);
        }
        private void HandleTo(JoinExpressionTreeVisitor to)
        {
            ModelMetadataRepository modelMetadataRepository = new ModelMetadataRepository();
            EntityModelType         entityModelType         = null;

            if (to.MemberContainingType != null)
            {
                entityModelType = modelMetadataRepository.GetModelMetadata(to.MemberContainingType);
            }

            if (entityModelType == null)
            {
                ToEntity    = to.EntityLogicalName;
                ToAttribute = to.MemberName;
            }
            else
            {
                ToEntity    = entityModelType.EntityLogicalName;
                ToAttribute = entityModelType.ParameterToAttributeLogicalName[to.MemberName];
            }
        }
        private void HandleFrom(JoinExpressionTreeVisitor from)
        {
            ModelMetadataRepository modelMetadataRepository = new ModelMetadataRepository();
            EntityModelType         entityModelType         = null;

            if (from.MemberContainingType != null)
            {
                entityModelType = modelMetadataRepository.GetModelMetadata(from.MemberContainingType);
            }

            if (entityModelType == null)
            {
                FromEntity    = from.EntityLogicalName;
                FromAttribute = from.MemberName;
            }
            else
            {
                FromEntity    = entityModelType.EntityLogicalName;
                FromAttribute = entityModelType.ParameterToAttributeLogicalName[from.MemberName];
            }
        }