예제 #1
0
        public NavigationPropertyBindingConfiguration HasOptionalBinding <TTargetType>(
            Expression <Func <TStructuralType, TTargetType> > navigationExpression,
            string targetEntitySet)
            where TTargetType : class
        {
            if (navigationExpression == null)
            {
                throw Error.ArgumentNull("navigationExpression");
            }

            if (String.IsNullOrEmpty(targetEntitySet))
            {
                throw Error.ArgumentNullOrEmpty("targetEntitySet");
            }

            NavigationPropertyConfiguration navigation = this._structuralType.HasOptional(navigationExpression);

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

            bindingPath.Add(navigation.PropertyInfo);

            NavigationSourceConfiguration entitySet = _modelBuilder.EntitySet <TTargetType>(targetEntitySet).Configuration;

            return(this._navigationSource.AddBinding(navigation, entitySet, bindingPath));
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingPathConfiguration{TStructuralType}"/> class.
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="structuralType">The type configuration.</param>
        /// <param name="navigationSource">The navigation source configuration.</param>
        /// <param name="bindingPath">The binding path.</param>
        public BindingPathConfiguration(ODataModelBuilder modelBuilder,
                                        StructuralTypeConfiguration <TStructuralType> structuralType,
                                        NavigationSourceConfiguration navigationSource,
                                        IList <MemberInfo> bindingPath)
        {
            if (modelBuilder == null)
            {
                throw Error.ArgumentNull("modelBuilder");
            }

            if (structuralType == null)
            {
                throw Error.ArgumentNull("structuralType");
            }

            if (navigationSource == null)
            {
                throw Error.ArgumentNull("navigationSource");
            }

            if (bindingPath == null)
            {
                throw Error.ArgumentNull("bindingPath");
            }

            _modelBuilder     = modelBuilder;
            _navigationSource = navigationSource;
            _structuralType   = structuralType;
            _bindingPath      = bindingPath;
        }
        public NavigationPropertyBindingConfiguration HasSingletonBinding <TTargetType, TDerivedEntityType>(
            Expression <Func <TDerivedEntityType, TTargetType> > navigationExpression,
            NavigationSourceConfiguration <TTargetType> targetSingleton)
            where TTargetType : class
            where TDerivedEntityType : class, TEntityType
        {
            if (navigationExpression == null)
            {
                throw Error.ArgumentNull("navigationExpression");
            }

            if (targetSingleton == null)
            {
                throw Error.ArgumentNull("targetSingleton");
            }

            EntityTypeConfiguration <TDerivedEntityType> derivedEntityType =
                _modelBuilder.EntityType <TDerivedEntityType>().DerivesFrom <TEntityType>();

            NavigationPropertyConfiguration navigation = derivedEntityType.HasRequired(navigationExpression);
            IList <MemberInfo> bindingPath             = new List <MemberInfo>
            {
                TypeHelper.AsMemberInfo(typeof(TDerivedEntityType)),
                navigation.PropertyInfo
            };

            return(this.Configuration.AddBinding(navigation, targetSingleton.Configuration, bindingPath));
        }
예제 #4
0
        /// <summary>
        /// Constructs an instance of an <see cref="NavigationSourceLinkBuilderAnnotation" /> from an <see cref="NavigationSourceConfiguration" />.
        /// </summary>
        public NavigationSourceLinkBuilderAnnotation(NavigationSourceConfiguration navigationSource)
        {
            if (navigationSource == null)
            {
                throw Error.ArgumentNull("navigationSource");
            }

            _idLinkBuilder   = navigationSource.GetIdLink();
            _editLinkBuilder = navigationSource.GetEditLink();
            _readLinkBuilder = navigationSource.GetReadLink();
        }
        /// <summary>
        /// Binds the given navigation property to the target navigation source.
        /// </summary>
        /// <param name="navigationConfiguration">The navigation property.</param>
        /// <param name="targetNavigationSource">The target navigation source.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>The <see cref="NavigationPropertyBindingConfiguration"/> so that it can be further configured.</returns>
        public virtual NavigationPropertyBindingConfiguration AddBinding(NavigationPropertyConfiguration navigationConfiguration,
                                                                         NavigationSourceConfiguration targetNavigationSource, IList <MemberInfo> bindingPath)
        {
            if (navigationConfiguration == null)
            {
                throw Error.ArgumentNull("navigationConfiguration");
            }

            if (targetNavigationSource == null)
            {
                throw Error.ArgumentNull("targetNavigationSource");
            }

            if (bindingPath == null || !bindingPath.Any())
            {
                throw Error.ArgumentNull("bindingPath");
            }

            VerifyBindingPath(navigationConfiguration, bindingPath);

            string path = bindingPath.ConvertBindingPath();

            Dictionary <string, NavigationPropertyBindingConfiguration> navigationPropertyBindingMap;
            NavigationPropertyBindingConfiguration navigationPropertyBinding;

            if (_navigationPropertyBindings.TryGetValue(navigationConfiguration, out navigationPropertyBindingMap))
            {
                if (navigationPropertyBindingMap.TryGetValue(path, out navigationPropertyBinding))
                {
                    if (navigationPropertyBinding.TargetNavigationSource != targetNavigationSource)
                    {
                        throw Error.NotSupported(SRResources.RebindingNotSupported);
                    }
                }
                else
                {
                    navigationPropertyBinding = new NavigationPropertyBindingConfiguration(navigationConfiguration,
                                                                                           targetNavigationSource, bindingPath);
                    _navigationPropertyBindings[navigationConfiguration][path] = navigationPropertyBinding;
                }
            }
            else
            {
                _navigationPropertyBindings[navigationConfiguration] =
                    new Dictionary <string, NavigationPropertyBindingConfiguration>();
                navigationPropertyBinding = new NavigationPropertyBindingConfiguration(navigationConfiguration,
                                                                                       targetNavigationSource, bindingPath);
                _navigationPropertyBindings[navigationConfiguration][path] = navigationPropertyBinding;
            }

            return(navigationPropertyBinding);
        }
        private void ApplyNavigationSourceConventions(NavigationSourceConfiguration navigationSourceConfiguration)
        {
            if (!_configuredNavigationSources.Contains(navigationSourceConfiguration))
            {
                _configuredNavigationSources.Add(navigationSourceConfiguration);

                foreach (INavigationSourceConvention convention in _conventions.OfType <INavigationSourceConvention>())
                {
                    if (convention != null)
                    {
                        convention.Apply(navigationSourceConfiguration, this);
                    }
                }
            }
        }
        public NavigationPropertyBindingConfiguration HasManyBinding <TTargetType>(
            Expression <Func <TEntityType, IEnumerable <TTargetType> > > navigationExpression,
            NavigationSourceConfiguration <TTargetType> targetEntitySet) where TTargetType : class
        {
            if (navigationExpression == null)
            {
                throw Error.ArgumentNull("navigationExpression");
            }

            if (targetEntitySet == null)
            {
                throw Error.ArgumentNull("targetEntitySet");
            }

            return(this.Configuration.AddBinding(EntityType.HasMany(navigationExpression), targetEntitySet.Configuration));
        }
        public NavigationPropertyBindingConfiguration HasSingletonBinding <TTargetType>(
            Expression <Func <TEntityType, TTargetType> > navigationExpression,
            NavigationSourceConfiguration <TTargetType> targetSingleton) where TTargetType : class
        {
            if (navigationExpression == null)
            {
                throw Error.ArgumentNull("navigationExpression");
            }

            if (targetSingleton == null)
            {
                throw Error.ArgumentNull("targetSingleton");
            }

            return(this.Configuration.AddBinding(EntityType.HasRequired(navigationExpression), targetSingleton.Configuration));
        }
        internal NavigationSourceConfiguration(ODataModelBuilder modelBuilder, NavigationSourceConfiguration configuration)
        {
            if (modelBuilder == null)
            {
                throw Error.ArgumentNull("modelBuilder");
            }

            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            _configuration = configuration;
            _modelBuilder  = modelBuilder;
            _entityType    = new EntityTypeConfiguration <TEntityType>(modelBuilder, _configuration.EntityType);
            _binding       = new BindingPathConfiguration <TEntityType>(modelBuilder, _entityType, _configuration);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationPropertyBindingConfiguration"/> class.
        /// </summary>
        /// <param name="navigationProperty">The navigation property for the binding.</param>
        /// <param name="navigationSource">The target navigation source of the binding.</param>
        /// <param name="path">The path of current binding.</param>
        public NavigationPropertyBindingConfiguration(NavigationPropertyConfiguration navigationProperty,
                                                      NavigationSourceConfiguration navigationSource, IList <MemberInfo> path)
        {
            if (navigationProperty == null)
            {
                throw Error.ArgumentNull("navigationProperty");
            }

            if (navigationSource == null)
            {
                throw Error.ArgumentNull("navigationSource");
            }

            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            NavigationProperty     = navigationProperty;
            TargetNavigationSource = navigationSource;
            Path = path;
        }
예제 #11
0
        public NavigationPropertyBindingConfiguration HasOptionalBinding <TTargetType, TDerivedType>(
            Expression <Func <TDerivedType, TTargetType> > navigationExpression,
            string targetEntitySet)
            where TTargetType : class
            where TDerivedType : class, TStructuralType
        {
            if (navigationExpression == null)
            {
                throw Error.ArgumentNull("navigationExpression");
            }

            if (String.IsNullOrEmpty(targetEntitySet))
            {
                throw Error.ArgumentNullOrEmpty("targetEntitySet");
            }

            StructuralTypeConfiguration <TDerivedType> derivedConfiguration;

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

            NavigationPropertyConfiguration navigation = derivedConfiguration.HasOptional(navigationExpression);

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

            bindingPath.Add(TypeHelper.AsMemberInfo(typeof(TDerivedType)));
            bindingPath.Add(navigation.PropertyInfo);

            NavigationSourceConfiguration entitySet = _modelBuilder.EntitySet <TTargetType>(targetEntitySet).Configuration;

            return(this._navigationSource.AddBinding(navigation, entitySet, bindingPath));
        }
        /// <summary>
        /// Binds the given navigation property to the target navigation source.
        /// </summary>
        /// <param name="navigationConfiguration">The navigation property.</param>
        /// <param name="targetNavigationSource">The target navigation source.</param>
        /// <returns>The <see cref="NavigationPropertyBindingConfiguration"/> so that it can be further configured.</returns>
        public virtual NavigationPropertyBindingConfiguration AddBinding(NavigationPropertyConfiguration navigationConfiguration,
                                                                         NavigationSourceConfiguration targetNavigationSource)
        {
            if (navigationConfiguration == null)
            {
                throw Error.ArgumentNull("navigationConfiguration");
            }

            if (targetNavigationSource == null)
            {
                throw Error.ArgumentNull("targetNavigationSource");
            }

            IList <MemberInfo> bindingPath = new List <MemberInfo> {
                navigationConfiguration.PropertyInfo
            };

            if (navigationConfiguration.DeclaringType != EntityType)
            {
                bindingPath.Insert(0, TypeHelper.AsMemberInfo(navigationConfiguration.DeclaringType.ClrType));
            }

            return(AddBinding(navigationConfiguration, targetNavigationSource, bindingPath));
        }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindingPathConfiguration{TStructuralType}"/> class.
 /// </summary>
 /// <param name="modelBuilder">The model builder.</param>
 /// <param name="structuralType">The type configuration.</param>
 /// <param name="navigationSource">The navigation source configuration.</param>
 public BindingPathConfiguration(ODataModelBuilder modelBuilder,
                                 StructuralTypeConfiguration <TStructuralType> structuralType,
                                 NavigationSourceConfiguration navigationSource)
     : this(modelBuilder, structuralType, navigationSource, new List <MemberInfo>())
 {
 }
 /// <summary>
 /// <see cref="SelectSupportConfiguration"/> configuration
 /// </summary>
 /// <typeparam name="TEntity">The entity type of the navigation source.</typeparam>
 /// <param name="navigationSource">The <see cref="IEdmNavigationSource"/> that can be built using <see cref="ODataModelBuilder"/>.</param>
 /// <returns><see cref="SelectSupportConfiguration"/></returns>
 public static SelectSupportConfiguration HasSelectSupport <TEntity>(this NavigationSourceConfiguration <TEntity> navigationSource) where TEntity : class
 => navigationSource?.Configuration.VocabularyTermConfigurations.GetOrCreateConfiguration <SelectSupportConfiguration>();
 /// <summary>
 /// Add vocabulary annotations to a model target.
 /// </summary>
 /// <param name="model"><see cref="EdmModel"/> to add annotations to</param>
 /// <param name="target"><see cref="EdmNavigationSource"/> to annotate</param>
 /// <param name="navigationSourceConfiguration"><see cref="NavigationSourceConfiguration"/> containing the collection of <see cref="VocabularyTermConfiguration"/> annotation configurations</param>
 public static void SetVocabularyConfigurationAnnotations(this EdmModel model, EdmNavigationSource target, NavigationSourceConfiguration navigationSourceConfiguration)
 => model.SetVocabularyConfigurationAnnotations(target as IEdmVocabularyAnnotatable, navigationSourceConfiguration?.VocabularyTermConfigurations.Values);
 /// <summary>
 /// <see cref="ChangeTrackingConfiguration"/> configuration
 /// </summary>
 /// <typeparam name="TEntity">The entity type of the navigation source.</typeparam>
 /// <param name="navigationSource">The <see cref="IEdmNavigationSource"/> that can be built using <see cref="ODataModelBuilder"/>.</param>
 /// <returns><see cref="ChangeTrackingConfiguration"/></returns>
 public static ChangeTrackingConfiguration HasChangeTracking <TEntity>(this NavigationSourceConfiguration <TEntity> navigationSource) where TEntity : class
 => navigationSource?.Configuration.VocabularyTermConfigurations.GetOrCreateConfiguration <ChangeTrackingConfiguration>();
 /// <summary>
 /// <see cref="NavigationRestrictionsConfiguration"/> configuration
 /// </summary>
 /// <typeparam name="TEntity">The entity type of the navigation source.</typeparam>
 /// <param name="navigationSource">The <see cref="IEdmNavigationSource"/> that can be built using <see cref="ODataModelBuilder"/>.</param>
 /// <returns><see cref="NavigationRestrictionsConfiguration"/></returns>
 public static NavigationRestrictionsConfiguration HasNavigationRestrictions <TEntity>(this NavigationSourceConfiguration <TEntity> navigationSource) where TEntity : class
 => navigationSource?.Configuration.VocabularyTermConfigurations.GetOrCreateConfiguration <NavigationRestrictionsConfiguration>();
 /// <summary>
 /// Initializes a new instance of the <see cref="NavigationPropertyBindingConfiguration"/> class.
 /// </summary>
 /// <param name="navigationProperty">The navigation property for the binding.</param>
 /// <param name="navigationSource">The target navigation source of the binding.</param>
 public NavigationPropertyBindingConfiguration(NavigationPropertyConfiguration navigationProperty,
                                               NavigationSourceConfiguration navigationSource)
     : this(navigationProperty, navigationSource, new MemberInfo[] { navigationProperty?.PropertyInfo })
 {
 }