コード例 #1
0
        public BindingPathConfiguration <TTargetType> HasManyPath <TTargetType>(
            Expression <Func <TStructuralType, IEnumerable <TTargetType> > > pathExpression,
            bool contained)
            where TTargetType : class
        {
            if (pathExpression == null)
            {
                throw Error.ArgumentNull("pathExpression");
            }

            PropertyInfo pathProperty = PropertySelectorVisitor.GetSelectedProperty(pathExpression);

            IList <MemberInfo> bindingPath = new List <MemberInfo>(_bindingPath);

            bindingPath.Add(pathProperty);

            StructuralTypeConfiguration <TTargetType> target;

            if (contained)
            {
                target = _modelBuilder.EntityType <TTargetType>();
                _structuralType.ContainsMany(pathExpression); // add a containment navigation property
            }
            else
            {
                target = _modelBuilder.ComplexType <TTargetType>();
                _structuralType.CollectionProperty(pathExpression); // add a collection complex property
            }

            return(new BindingPathConfiguration <TTargetType>(_modelBuilder, target, _navigationSource, bindingPath));
        }
コード例 #2
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);
        }
コード例 #3
0
        public BindingPathConfiguration <TTargetType> HasSinglePath <TTargetType, TDerivedType>(
            Expression <Func <TDerivedType, TTargetType> > pathExpression,
            bool required,
            bool contained)
            where TTargetType : class
            where TDerivedType : class, TStructuralType
        {
            if (pathExpression == null)
            {
                throw Error.ArgumentNull("pathExpression");
            }

            PropertyInfo pathProperty = PropertySelectorVisitor.GetSelectedProperty(pathExpression);

            IList <MemberInfo> bindingPath = new List <MemberInfo>(_bindingPath);

            bindingPath.Add(TypeHelper.AsMemberInfo(typeof(TDerivedType)));
            bindingPath.Add(pathProperty);

            // make sure the derived type has the same type kind with the resource type.
            StructuralTypeConfiguration <TDerivedType> derivedConfiguration;

            if (_structuralType.Configuration.Kind == EdmTypeKind.Entity)
            {
                derivedConfiguration = _modelBuilder.EntityType <TDerivedType>().DerivesFrom <TStructuralType>();
            }
            else
            {
                derivedConfiguration = _modelBuilder.ComplexType <TDerivedType>().DerivesFrom <TStructuralType>();
            }

            StructuralTypeConfiguration <TTargetType> target;

            if (contained)
            {
                target = _modelBuilder.EntityType <TTargetType>();

                if (required)
                {
                    derivedConfiguration.ContainsRequired(pathExpression);
                }
                else
                {
                    derivedConfiguration.ContainsOptional(pathExpression);
                }
            }
            else
            {
                target = _modelBuilder.ComplexType <TTargetType>();
                derivedConfiguration.ComplexProperty(pathExpression).NullableProperty = !required;
            }

            return(new BindingPathConfiguration <TTargetType>(_modelBuilder, target, _navigationSource, bindingPath));
        }
コード例 #4
0
        public BindingPathConfiguration <TTargetType> HasSinglePath <TTargetType>(
            Expression <Func <TStructuralType, TTargetType> > pathExpression,
            bool required,
            bool contained)
            where TTargetType : class
        {
            if (pathExpression == null)
            {
                throw Error.ArgumentNull("pathExpression");
            }

            PropertyInfo pathProperty = PropertySelectorVisitor.GetSelectedProperty(pathExpression);

            IList <MemberInfo> bindingPath = new List <MemberInfo>(_bindingPath);

            bindingPath.Add(pathProperty);

            StructuralTypeConfiguration <TTargetType> target;

            if (contained)
            {
                target = _modelBuilder.EntityType <TTargetType>();

                if (required)
                {
                    _structuralType.ContainsRequired(pathExpression);
                }
                else
                {
                    _structuralType.ContainsOptional(pathExpression);
                }
            }
            else
            {
                target = _modelBuilder.ComplexType <TTargetType>();
                _structuralType.ComplexProperty(pathExpression).NullableProperty = !required;
            }

            return(new BindingPathConfiguration <TTargetType>(_modelBuilder, target, _navigationSource, bindingPath));
        }