public void CanGetSingleSelectedProperty()
        {
            Expression <Func <AddressEntity, int> > expr = a => a.ID;
            var properties = PropertySelectorVisitor.GetSelectedProperties(expr).ToArray();

            Assert.Equal(1, properties.Length);
            Assert.Equal("ID", properties[0].Name);
        }
        public void CanGetMultipleSelectedProperties()
        {
            var expr       = Expr((AddressEntity a) => new { a.ID, a.ZipCode });
            var properties = PropertySelectorVisitor.GetSelectedProperties(expr).ToArray();

            Assert.Equal(2, properties.Length);
            Assert.Equal("ID", properties[0].Name);
            Assert.Equal("ZipCode", properties[1].Name);
        }
Example #3
0
        public EntityTypeConfiguration <TEntityType> HasKey <TKey>(Expression <Func <TEntityType, TKey> > keyDefinitionExpression)
        {
            ICollection <PropertyInfo> properties = PropertySelectorVisitor.GetSelectedProperties(keyDefinitionExpression);

            foreach (PropertyInfo property in properties)
            {
                _configuration.HasKey(property);
            }
            return(this);
        }
        public void FailOnUnsupportedExpressionNodeType()
        {
            Expression <Func <AddressEntity, AddressEntity> > expr = (a) => CreateAddress(a.ID);
            var exception = Assert.Throws <NotSupportedException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal("Unsupported Expression NodeType.", exception.Message);
        }
        public void FailWhenMemberExpressionNotBoundToParameter()
        {
            Expression <Func <AddressEntity, int> > expr = (a) => new AddressEntity().ID;
            var exception = Assert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal("MemberExpressions must be bound to the LambdaExpression parameter.", exception.Message);
        }
        public void FailWhenLambdaExpressionHasMoreThanOneParameter()
        {
            Expression <Func <AddressEntity, AddressEntity, int> > expr = (a1, a2) => a1.ID;
            var exception = Assert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal("The LambdaExpression must have exactly one parameter.", exception.Message);
        }
        public void FailWhenLambdaExpressionAccessesFields()
        {
            Expression <Func <WorkItem, int> > expr = w => w.Field;
            var exception = Assert.Throws <InvalidOperationException>(() =>
            {
                var properties = PropertySelectorVisitor.GetSelectedProperties(expr);
            });

            Assert.Equal(string.Format("Member '{0}.Field' is not a property.", typeof(WorkItem).FullName), exception.Message);
        }
Example #8
0
        private PrimitivePropertyConfiguration GetPrimitivePropertyConfiguration(Expression propertyExpression, bool optional = false)
        {
            PropertyInfo propertyInfo = PropertySelectorVisitor.GetSelectedProperty(propertyExpression);
            PrimitivePropertyConfiguration property = _configuration.AddProperty(propertyInfo);

            if (optional)
            {
                property.IsOptional();
            }

            return(property);
        }
Example #9
0
        private ComplexPropertyConfiguration GetComplexPropertyConfiguration(Expression propertyExpression, bool optional = false)
        {
            PropertyInfo propertyInfo             = PropertySelectorVisitor.GetSelectedProperty(propertyExpression);
            ComplexPropertyConfiguration property = _configuration.AddComplexProperty(propertyInfo);

            if (optional)
            {
                property.IsOptional();
            }
            else
            {
                property.IsRequired();
            }

            return(property);
        }
Example #10
0
        internal NavigationPropertyConfiguration GetOrCreateNavigationProperty(Expression navigationPropertyExpression, EdmMultiplicity multiplicity)
        {
            PropertyInfo navigationProperty = PropertySelectorVisitor.GetSelectedProperty(navigationPropertyExpression);

            return(_configuration.AddNavigationProperty(navigationProperty, multiplicity));
        }
Example #11
0
        public virtual void Ignore <TProperty>(Expression <Func <TStructuralType, TProperty> > propertyExpression)
        {
            PropertyInfo ignoredProperty = PropertySelectorVisitor.GetSelectedProperty(propertyExpression);

            _configuration.RemoveProperty(ignoredProperty);
        }