Пример #1
0
        public static bool NamesMatch(string actualName, string requestedName, IPluralizer pluralizer)
        {
            actualName    = actualName.Split('.').Last().Homogenize();
            requestedName = requestedName.Split('.').Last().Homogenize();

            return(actualName == requestedName || pluralizer != null &&
                   (actualName == pluralizer.Singularize(requestedName) ||
                    actualName == pluralizer.Pluralize(requestedName) ||
                    pluralizer.Singularize(actualName) == requestedName ||
                    pluralizer.Pluralize(actualName) == requestedName));
        }
Пример #2
0
        public bool IsMatch(string actualName, string requestedName)
        {
            actualName    = actualName.Split('.').Last().Homogenize();
            requestedName = requestedName.Split('.').Last().Homogenize();

            return(actualName == requestedName ||
                   (actualName == _pluralizer.Singularize(requestedName) ||
                    actualName == _pluralizer.Pluralize(requestedName) ||
                    _pluralizer.Singularize(actualName) == requestedName ||
                    _pluralizer.Pluralize(actualName) == requestedName));
        }
Пример #3
0
        public string GetEnvelopePropertyName(Type type)
        {
            if (type.IsArray)
            {
                var elementType = type.GetElementType();
                return(pluralizer.Pluralize(GetEnvelopeTypeName(elementType)));
            }

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                if (!type.GetGenericArguments().Any())
                {
                    return(pluralizer.Pluralize(type.Name));
                }

                var arg = type.GetGenericArguments()[0];
                return(pluralizer.Pluralize(GetEnvelopeTypeName(arg)));
            }

            return(GetEnvelopeTypeName(type));
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey foreignKey)
        {
            Check.NotNull(foreignKey, nameof(foreignKey));

            var dependentEndExistingIdentifiers             = ExistingIdentifiers(foreignKey.DeclaringEntityType);
            var dependentEndNavigationPropertyCandidateName =
                _candidateNamingService.GetDependentEndCandidateNavigationPropertyName(foreignKey);
            var dependentEndNavigationPropertyName =
                _cSharpUtilities.GenerateCSharpIdentifier(
                    dependentEndNavigationPropertyCandidateName,
                    dependentEndExistingIdentifiers,
                    singularizePluralizer: null,
                    uniquifier: NavigationUniquifier);

            foreignKey.SetDependentToPrincipal(dependentEndNavigationPropertyName);

            if (foreignKey.DeclaringEntityType.IsKeyless)
            {
                return;
            }

            var principalEndExistingIdentifiers             = ExistingIdentifiers(foreignKey.PrincipalEntityType);
            var principalEndNavigationPropertyCandidateName = foreignKey.IsSelfReferencing()
                ? string.Format(
                CultureInfo.CurrentCulture,
                SelfReferencingPrincipalEndNavigationNamePattern,
                dependentEndNavigationPropertyName)
                : _candidateNamingService.GetPrincipalEndCandidateNavigationPropertyName(
                foreignKey, dependentEndNavigationPropertyName);

            if (!foreignKey.IsUnique &&
                !foreignKey.IsSelfReferencing())
            {
                principalEndNavigationPropertyCandidateName = _options.NoPluralize
                    ? principalEndNavigationPropertyCandidateName
                    : _pluralizer.Pluralize(principalEndNavigationPropertyCandidateName);
            }

            var principalEndNavigationPropertyName =
                _cSharpUtilities.GenerateCSharpIdentifier(
                    principalEndNavigationPropertyCandidateName,
                    principalEndExistingIdentifiers,
                    singularizePluralizer: null,
                    uniquifier: NavigationUniquifier);

            foreignKey.SetPrincipalToDependent(principalEndNavigationPropertyName);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected virtual void AddNavigationProperties(IMutableForeignKey foreignKey)
        {
            if (foreignKey == null)
            {
                throw new ArgumentNullException(nameof(foreignKey));
            }

            var dependentEndExistingIdentifiers             = ExistingIdentifiers(foreignKey.DeclaringEntityType);
            var dependentEndNavigationPropertyCandidateName =
                _candidateNamingService.GetDependentEndCandidateNavigationPropertyName(foreignKey);
            var dependentEndNavigationPropertyName =
                _cSharpUtilities.GenerateCSharpIdentifier(
                    dependentEndNavigationPropertyCandidateName,
                    dependentEndExistingIdentifiers,
                    singularizePluralizer: null,
                    uniquifier: NavigationUniquifier);

            foreignKey.HasDependentToPrincipal(dependentEndNavigationPropertyName);

            var principalEndExistingIdentifiers             = ExistingIdentifiers(foreignKey.PrincipalEntityType);
            var principalEndNavigationPropertyCandidateName = foreignKey.IsSelfReferencing()
                ? string.Format(
                CultureInfo.CurrentCulture,
                SelfReferencingPrincipalEndNavigationNamePattern,
                dependentEndNavigationPropertyName)
                : _candidateNamingService.GetPrincipalEndCandidateNavigationPropertyName(
                foreignKey, dependentEndNavigationPropertyName);

            if (!foreignKey.IsUnique &&
                !foreignKey.IsSelfReferencing())
            {
                principalEndNavigationPropertyCandidateName = _pluralizer.Pluralize(principalEndNavigationPropertyCandidateName);
            }

            var principalEndNavigationPropertyName =
                _cSharpUtilities.GenerateCSharpIdentifier(
                    principalEndNavigationPropertyCandidateName,
                    principalEndExistingIdentifiers,
                    singularizePluralizer: null,
                    uniquifier: NavigationUniquifier);

            foreignKey.HasPrincipalToDependent(principalEndNavigationPropertyName);
        }
Пример #6
0
 protected virtual string GetDbSetName([NotNull] TableModel table)
 => _pluralizer.Pluralize(_tableNamer.GetName(Check.NotNull(table, nameof(table))));
Пример #7
0
        private IEdmModel BuildEdmModel()
        {
            var builder = new ODataConventionModelBuilder();

            // General Entities
            builder.EntityType <House>();
            builder.EntitySet <House>("Houses");
            builder.EntityType <Room>();
            builder.EntitySet <Room>("Rooms");

            // Interior definition (user-defined properties)
            builder.EntityType <InteriorDefinition>()
            .HasMany(d => d.Properties).AutomaticallyExpand(true);
            builder.EntitySet <InteriorDefinition>("InteriorDefinitions");

            builder.EntityType <InteriorPropertyDefinition>();
            builder.EnumType <InteriorPropertyType>();

            // Register base type of interiors and ignore user-defined properties
            // they are defined below according to the current DB confiuration
            var interiorTypeConfiguration = builder.EntityType <Interior>();

            interiorTypeConfiguration.Ignore(i => i.DefinitionID);
            interiorTypeConfiguration.Ignore(i => i.Definition);
            interiorTypeConfiguration.Ignore(i => i.StringProperty1);
            interiorTypeConfiguration.Ignore(i => i.StringProperty2);
            interiorTypeConfiguration.Ignore(i => i.StringProperty3);
            interiorTypeConfiguration.Ignore(i => i.IntProperty1);
            interiorTypeConfiguration.Ignore(i => i.IntProperty2);
            interiorTypeConfiguration.Ignore(i => i.IntProperty3);
            interiorTypeConfiguration.Ignore(i => i.DoubleProperty1);
            interiorTypeConfiguration.Ignore(i => i.DoubleProperty2);
            interiorTypeConfiguration.Ignore(i => i.DoubleProperty3);
            builder.EntitySet <Interior>("Interior");

            // Build the intermediate model and register all dynamic interior definitions
            var model          = (EdmModel)builder.GetEdmModel();
            var entityType     = (IEdmEntityType)model.FindDeclaredType(interiorTypeConfiguration.FullName);
            var container      = (EdmEntityContainer)model.EntityContainer;
            var ns             = model.SchemaElements.First().Namespace;
            var propertyLookup = BuildPropertyLookup(typeof(IUserDefinedPropertyBag));

            var definitions = _houseContext.InteriorDefinitions.Include(d => d.Properties).ToArray();

            foreach (var definition in definitions)
            {
                // register type by name using the Interior as base type.
                var type = new EdmEntityType(ns, definition.Name, entityType, false, false);
                // define the correct CLR type as backstore
                model.SetAnnotationValue(type, new ClrTypeAnnotation(typeof(Interior)));
                // remember which interior definition represents this EDM type.
                model.SetAnnotationValue(type, new InteriorDefinitionAnnotation(definition.ID));
                // register user defined properties
                foreach (var property in definition.Properties)
                {
                    var edmProperty = type.AddStructuralProperty(property.Name, MapToEdmType(property.PropertyType));
                    model.SetAnnotationValue(edmProperty, new ClrPropertyInfoAnnotation(propertyLookup[property.PropertyName].Single()));
                }

                // add to model and register entity set
                model.AddElement(type);
                container.AddEntitySet(_pluralizer.Pluralize(definition.Name), type);
            }

            // Register type mapping handler which translates Interiors correctly.
            model.SetAnnotationValue <IEdmModelClrTypeMappingHandler>(model, new InteriorDefinitionAwareClrTypeMappingHandler());

            // validate the model again newly added entities
            if (!model.Validate(out var errors))
            {
                Debug.Fail("EDM is not valid", string.Join(Environment.NewLine, errors.Select(e => e.ToString())));
            }

            return(model);
        }
 public string Pluralize(string word)
 {
     return(plurals.GetOrAdd(word, x => pluralizer.Pluralize(x)));
 }
 private static Dictionary <string, WeightUnit> GetParsableUnitsByPluralizedNames(IPluralizer pluralizer) =>
 WeightUnit
 .GetPredefinedUnits()
 .ToDictionary(e => pluralizer.Pluralize(e.Name));