private bool TryBindProperty(Expression source, MemberIdentity member, out SqlExpression expression)
        {
            if (source is EntityShaperExpression entityShaperExpression)
            {
                var projectionBindingExpression = (ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression;
                var selectExpression            = ((SelectExpression)projectionBindingExpression.QueryExpression);

                var entityType = entityShaperExpression.EntityType;
                var property   = member.MemberInfo != null
                    ? entityType.FindProperty(member.MemberInfo)
                    : entityType.FindProperty(member.Name);

                if (property != null)
                {
                    expression = selectExpression.BindProperty(property, projectionBindingExpression);
                    return(true);
                }

                var navigation = member.MemberInfo != null
                    ? entityType.FindNavigation(member.MemberInfo)
                    : entityType.FindNavigation(member.Name);

                expression = selectExpression.BindNavigation(navigation, projectionBindingExpression);
                return(true);
            }
            else if (source is ObjectAccessExpression objectAccessExpression)
            {
                var entityType = objectAccessExpression.Navigation.GetTargetType();
                var property   = member.MemberInfo != null
                    ? entityType.FindProperty(member.MemberInfo)
                    : entityType.FindProperty(member.Name);

                if (property != null)
                {
                    expression = new KeyAccessExpression(property, objectAccessExpression);
                    return(true);
                }

                var navigation = member.MemberInfo != null
                    ? entityType.FindNavigation(member.MemberInfo)
                    : entityType.FindNavigation(member.Name);

                expression = new ObjectAccessExpression(navigation, objectAccessExpression);
                return(true);
            }

            expression = null;
            return(false);
        }
Ejemplo n.º 2
0
        public KeyAccessExpression GetProperty(IProperty property)
        {
            if (!_entityType.GetTypesInHierarchy().Contains(property.DeclaringEntityType))
            {
                throw new InvalidOperationException(
                          $"Called EntityProjectionExpression.GetProperty() with incorrect IProperty. EntityType:{_entityType.DisplayName()}, Property:{property.Name}");
            }

            if (!_propertyExpressionsCache.TryGetValue(property, out var expression))
            {
                expression = new KeyAccessExpression(property, AccessExpression);
                _propertyExpressionsCache[property] = expression;
            }

            return(expression);
        }
Ejemplo n.º 3
0
        private bool TryBindProperty(Expression source, MemberIdentity member, out SqlExpression expression)
        {
            if (source is EntityProjectionExpression entityProjectionExpression)
            {
                var entityType = entityProjectionExpression.EntityType;
                var property   = member.MemberInfo != null
                    ? entityType.FindProperty(member.MemberInfo)
                    : entityType.FindProperty(member.Name);

                if (property != null)
                {
                    expression = entityProjectionExpression.BindProperty(property);
                    return(true);
                }

                var navigation = member.MemberInfo != null
                    ? entityType.FindNavigation(member.MemberInfo)
                    : entityType.FindNavigation(member.Name);

                expression = entityProjectionExpression.BindNavigation(navigation);
                return(true);
            }
            else if (source is ObjectAccessExpression objectAccessExpression)
            {
                var entityType = objectAccessExpression.Navigation.GetTargetType();
                var property   = member.MemberInfo != null
                    ? entityType.FindProperty(member.MemberInfo)
                    : entityType.FindProperty(member.Name);

                if (property != null)
                {
                    expression = new KeyAccessExpression(property, objectAccessExpression);
                    return(true);
                }

                var navigation = member.MemberInfo != null
                    ? entityType.FindNavigation(member.MemberInfo)
                    : entityType.FindNavigation(member.Name);

                expression = new ObjectAccessExpression(navigation, objectAccessExpression);
                return(true);
            }

            expression = null;
            return(false);
        }
        public SqlExpression BindProperty(IProperty property)
        {
            if (!EntityType.IsAssignableFrom(property.DeclaringEntityType) &&
                !property.DeclaringEntityType.IsAssignableFrom(EntityType))
            {
                throw new InvalidOperationException(
                          $"Called EntityProjectionExpression.GetProperty() with incorrect IProperty. EntityType:{EntityType.DisplayName()}, Property:{property.Name}");
            }

            if (!_propertyExpressionsCache.TryGetValue(property, out var expression))
            {
                expression = new KeyAccessExpression(property, AccessExpression);
                _propertyExpressionsCache[property] = expression;
            }

            return(expression);
        }
 protected abstract Expression VisitKeyAccess(KeyAccessExpression keyAccessExpression);
Ejemplo n.º 6
0
        protected override Expression VisitKeyAccess(KeyAccessExpression keyAccessExpression)
        {
            _sqlBuilder.Append(keyAccessExpression);

            return(keyAccessExpression);
        }