/// <summary>
        ///     Disables one or more conventions for the <see cref="DbModelBuilder" />.
        /// </summary>
        /// <param name="conventions"> The conventions to be disabled. </param>
        public void Remove(params IConvention[] conventions)
        {
            Check.NotNull(conventions, "conventions");

            Check.NotNull(conventions, "conventions");
            Debug.Assert(conventions.All(c => c != null));

            foreach (var c in conventions)
            {
                if (ConventionsTypeFilter.IsConfigurationConvention(c.GetType()))
                {
                    _configurationConventions.Remove(c);
                }

                if (ConventionsTypeFilter.IsConceptualModelConvention(c.GetType()))
                {
                    _conceptualModelConventions.Remove(c);
                }

                if (ConventionsTypeFilter.IsStoreModelConvention(c.GetType()))
                {
                    _storeModelConventions.Remove(c);
                }

                if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(c.GetType()))
                {
                    _conceptualToStoreMappingConventions.Remove(c);
                }
            }
        }
Example #2
0
        public void AddBefore <TExistingConvention>(IConvention newConvention) where TExistingConvention : IConvention
        {
            Check.NotNull <IConvention>(newConvention, nameof(newConvention));
            bool flag = true;

            if (ConventionsTypeFilter.IsConfigurationConvention(newConvention.GetType()) && ConventionsTypeFilter.IsConfigurationConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._configurationConventions);
            }
            if (ConventionsTypeFilter.IsConceptualModelConvention(newConvention.GetType()) && ConventionsTypeFilter.IsConceptualModelConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._conceptualModelConventions);
            }
            if (ConventionsTypeFilter.IsStoreModelConvention(newConvention.GetType()) && ConventionsTypeFilter.IsStoreModelConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._storeModelConventions);
            }
            if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(newConvention.GetType()) && ConventionsTypeFilter.IsConceptualToStoreMappingConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._conceptualToStoreMappingConventions);
            }
            if (flag)
            {
                throw new InvalidOperationException(Strings.ConventionsConfiguration_ConventionTypeMissmatch((object)newConvention.GetType(), (object)typeof(TExistingConvention)));
            }
        }
Example #3
0
 /// <summary>
 ///     Enables one or more conventions for the <see cref="T:System.Data.Entity.DbModelBuilder" />.
 /// </summary>
 /// <param name="conventions"> The conventions to be enabled. </param>
 public void Add(params IConvention[] conventions)
 {
     Check.NotNull <IConvention[]>(conventions, nameof(conventions));
     foreach (IConvention convention in conventions)
     {
         bool flag = true;
         if (ConventionsTypeFilter.IsConfigurationConvention(convention.GetType()))
         {
             flag = false;
             int index = this._configurationConventions.FindIndex((Predicate <IConvention>)(initialConvention => this._initialConventionSet.ConfigurationConventions.Contains <IConvention>(initialConvention)));
             this._configurationConventions.Insert(index == -1 ? this._configurationConventions.Count : index, convention);
         }
         if (ConventionsTypeFilter.IsConceptualModelConvention(convention.GetType()))
         {
             flag = false;
             this._conceptualModelConventions.Add(convention);
         }
         if (ConventionsTypeFilter.IsStoreModelConvention(convention.GetType()))
         {
             flag = false;
             this._storeModelConventions.Add(convention);
         }
         if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(convention.GetType()))
         {
             flag = false;
             this._conceptualToStoreMappingConventions.Add(convention);
         }
         if (flag)
         {
             throw new InvalidOperationException(Strings.ConventionsConfiguration_InvalidConventionType((object)convention.GetType()));
         }
     }
 }
Example #4
0
 public virtual bool IsConvention(Type conventionType)
 {
     if (!ConventionsTypeFilter.IsConfigurationConvention(conventionType) && !ConventionsTypeFilter.IsConceptualModelConvention(conventionType) && !ConventionsTypeFilter.IsConceptualToStoreMappingConvention(conventionType))
     {
         return(ConventionsTypeFilter.IsStoreModelConvention(conventionType));
     }
     return(true);
 }
        /// <summary>
        ///     Enables one or more conventions for the <see cref="DbModelBuilder" />.
        /// </summary>
        /// <param name="conventions"> The conventions to be enabled. </param>
        public void Add(params IConvention[] conventions)
        {
            Check.NotNull(conventions, "conventions");
            Debug.Assert(conventions.All(c => c != null));

            foreach (var c in conventions)
            {
                var invalidType = true;

                if (ConventionsTypeFilter.IsConfigurationConvention(c.GetType()))
                {
                    invalidType = false;
                    var existingConventionIndex = _configurationConventions.FindIndex(
                        initialConvention => _initialConventionSet.ConfigurationConventions.Contains(initialConvention));
                    existingConventionIndex = existingConventionIndex == -1
                            ? _configurationConventions.Count
                            : existingConventionIndex;
                    _configurationConventions.Insert(existingConventionIndex, c);
                }

                if (ConventionsTypeFilter.IsConceptualModelConvention(c.GetType()))
                {
                    invalidType = false;
                    _conceptualModelConventions.Add(c);
                }

                if (ConventionsTypeFilter.IsStoreModelConvention(c.GetType()))
                {
                    invalidType = false;
                    _storeModelConventions.Add(c);
                }

                if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(c.GetType()))
                {
                    invalidType = false;
                    _conceptualToStoreMappingConventions.Add(c);
                }

                if (invalidType)
                {
                    throw new InvalidOperationException(
                              Strings.ConventionsConfiguration_InvalidConventionType(c.GetType()));
                }
            }
        }
        public void AddBefore <TExistingConvention>(IConvention newConvention)
            where TExistingConvention : IConvention
        {
            Check.NotNull(newConvention, "newConvention");

            var typeMissmatch = true;

            if (ConventionsTypeFilter.IsConfigurationConvention(newConvention.GetType()) &&
                ConventionsTypeFilter.IsConfigurationConvention(typeof(TExistingConvention)))
            {
                typeMissmatch = false;
                Insert(typeof(TExistingConvention), 0, newConvention, _configurationConventions);
            }

            if (ConventionsTypeFilter.IsConceptualModelConvention(newConvention.GetType()) &&
                ConventionsTypeFilter.IsConceptualModelConvention(typeof(TExistingConvention)))
            {
                typeMissmatch = false;
                Insert(typeof(TExistingConvention), 0, newConvention, _conceptualModelConventions);
            }

            if (ConventionsTypeFilter.IsStoreModelConvention(newConvention.GetType()) &&
                ConventionsTypeFilter.IsStoreModelConvention(typeof(TExistingConvention)))
            {
                typeMissmatch = false;
                Insert(typeof(TExistingConvention), 0, newConvention, _storeModelConventions);
            }

            if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(newConvention.GetType()) &&
                ConventionsTypeFilter.IsConceptualToStoreMappingConvention(typeof(TExistingConvention)))
            {
                typeMissmatch = false;
                Insert(typeof(TExistingConvention), 0, newConvention, _conceptualToStoreMappingConventions);
            }

            if (typeMissmatch)
            {
                throw new InvalidOperationException(
                          Strings.ConventionsConfiguration_ConventionTypeMissmatch(
                              newConvention.GetType(), typeof(TExistingConvention)));
            }
        }
        internal ConventionsConfiguration(ConventionSet conventionSet)
        {
            DebugCheck.NotNull(conventionSet);
            Debug.Assert(
                conventionSet.ConfigurationConventions.All(c => c != null && ConventionsTypeFilter.IsConfigurationConvention(c.GetType())));
            Debug.Assert(
                conventionSet.ConceptualModelConventions.All(
                    c => c != null && ConventionsTypeFilter.IsConceptualModelConvention(c.GetType())));
            Debug.Assert(
                conventionSet.ConceptualToStoreMappingConventions.All(
                    c => c != null && ConventionsTypeFilter.IsConceptualToStoreMappingConvention(c.GetType())));
            Debug.Assert(
                conventionSet.StoreModelConventions.All(c => c != null && ConventionsTypeFilter.IsStoreModelConvention(c.GetType())));

            _configurationConventions.AddRange(conventionSet.ConfigurationConventions);
            _conceptualModelConventions.AddRange(conventionSet.ConceptualModelConventions);
            _conceptualToStoreMappingConventions.AddRange(conventionSet.ConceptualToStoreMappingConventions);
            _storeModelConventions.AddRange(conventionSet.StoreModelConventions);
            _initialConventionSet = conventionSet;
        }
Example #8
0
 public void Remove <TConvention>() where TConvention : IConvention
 {
     if (ConventionsTypeFilter.IsConfigurationConvention(typeof(TConvention)))
     {
         this._configurationConventions.RemoveAll((Predicate <IConvention>)(c => c.GetType() == typeof(TConvention)));
     }
     if (ConventionsTypeFilter.IsConceptualModelConvention(typeof(TConvention)))
     {
         this._conceptualModelConventions.RemoveAll((Predicate <IConvention>)(c => c.GetType() == typeof(TConvention)));
     }
     if (ConventionsTypeFilter.IsStoreModelConvention(typeof(TConvention)))
     {
         this._storeModelConventions.RemoveAll((Predicate <IConvention>)(c => c.GetType() == typeof(TConvention)));
     }
     if (!ConventionsTypeFilter.IsConceptualToStoreMappingConvention(typeof(TConvention)))
     {
         return;
     }
     this._conceptualToStoreMappingConventions.RemoveAll((Predicate <IConvention>)(c => c.GetType() == typeof(TConvention)));
 }
        public void Remove <TConvention>()
            where TConvention : IConvention
        {
            if (ConventionsTypeFilter.IsConfigurationConvention(typeof(TConvention)))
            {
                _configurationConventions.RemoveAll(c => c.GetType() == typeof(TConvention));
            }

            if (ConventionsTypeFilter.IsConceptualModelConvention(typeof(TConvention)))
            {
                _conceptualModelConventions.RemoveAll(c => c.GetType() == typeof(TConvention));
            }

            if (ConventionsTypeFilter.IsStoreModelConvention(typeof(TConvention)))
            {
                _storeModelConventions.RemoveAll(c => c.GetType() == typeof(TConvention));
            }

            if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(typeof(TConvention)))
            {
                _conceptualToStoreMappingConventions.RemoveAll(c => c.GetType() == typeof(TConvention));
            }
        }
Example #10
0
 /// <summary>
 ///     Disables one or more conventions for the <see cref="T:System.Data.Entity.DbModelBuilder" />.
 /// </summary>
 /// <param name="conventions"> The conventions to be disabled. </param>
 public void Remove(params IConvention[] conventions)
 {
     Check.NotNull <IConvention[]>(conventions, nameof(conventions));
     Check.NotNull <IConvention[]>(conventions, nameof(conventions));
     foreach (IConvention convention in conventions)
     {
         if (ConventionsTypeFilter.IsConfigurationConvention(convention.GetType()))
         {
             this._configurationConventions.Remove(convention);
         }
         if (ConventionsTypeFilter.IsConceptualModelConvention(convention.GetType()))
         {
             this._conceptualModelConventions.Remove(convention);
         }
         if (ConventionsTypeFilter.IsStoreModelConvention(convention.GetType()))
         {
             this._storeModelConventions.Remove(convention);
         }
         if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(convention.GetType()))
         {
             this._conceptualToStoreMappingConventions.Remove(convention);
         }
     }
 }