示例#1
0
        private void Process(IConventionEntityTypeBuilder entityTypeBuilder)
        {
            var entityType = entityTypeBuilder.Metadata;
            var candidates = entityType.GetRuntimeProperties().Values;

            foreach (var propertyInfo in candidates)
            {
                var name = propertyInfo.GetSimpleMemberName();
                if (entityTypeBuilder.IsIgnored(name) ||
                    entityType.FindProperty(propertyInfo) != null ||
                    entityType.FindNavigation(propertyInfo) != null ||
                    !propertyInfo.IsCandidateProperty(publicOnly: false) ||
                    (propertyInfo.IsCandidateProperty() &&
                     Dependencies.TypeMappingSource.FindMapping(propertyInfo) != null))
                {
                    continue;
                }

                var factory = Dependencies.ParameterBindingFactories.FindFactory(propertyInfo.PropertyType, name);
                if (factory == null)
                {
                    continue;
                }

                entityTypeBuilder.ServiceProperty(propertyInfo)?.HasParameterBinding(
                    (ServiceParameterBinding)factory.Bind(entityType, propertyInfo.PropertyType, name));
            }
        }
示例#2
0
        private void Process(IConventionEntityTypeBuilder entityTypeBuilder)
        {
            var entityType = entityTypeBuilder.Metadata;

            if (!entityType.HasClrType())
            {
                return;
            }

            var candidates = entityType.GetRuntimeProperties().Values;

            foreach (var propertyInfo in candidates)
            {
                var name = propertyInfo.GetSimpleMemberName();
                if (entityTypeBuilder.IsIgnored(name) ||
                    entityType.FindProperty(propertyInfo) != null ||
                    entityType.FindNavigation(propertyInfo) != null ||
                    !propertyInfo.IsCandidateProperty(publicOnly: false) ||
                    (propertyInfo.IsCandidateProperty() &&
                     Dependencies.TypeMappingSource.FindMapping(propertyInfo) != null))
                {
                    continue;
                }

                var factory = Dependencies.ParameterBindingFactories.FindFactory(propertyInfo.PropertyType, name);
                if (factory == null)
                {
                    continue;
                }

                var duplicateMap = GetDuplicateServiceProperties(entityType);
                if (duplicateMap != null &&
                    duplicateMap.TryGetValue(propertyInfo.PropertyType, out var duplicateServiceProperties))
                {
                    duplicateServiceProperties.Add(propertyInfo);

                    return;
                }

                var otherServicePropertySameType = entityType.GetServiceProperties()
                                                   .FirstOrDefault(p => p.ClrType == propertyInfo.PropertyType);
                if (otherServicePropertySameType != null)
                {
                    if (ConfigurationSource.Convention.Overrides(otherServicePropertySameType.GetConfigurationSource()))
                    {
                        otherServicePropertySameType.DeclaringEntityType.RemoveServiceProperty(otherServicePropertySameType.Name);
                    }

                    AddDuplicateServiceProperty(entityTypeBuilder, propertyInfo);
                    AddDuplicateServiceProperty(entityTypeBuilder, otherServicePropertySameType.GetIdentifyingMemberInfo());

                    return;
                }

                entityTypeBuilder.ServiceProperty(propertyInfo)?.HasParameterBinding(
                    (ServiceParameterBinding)factory.Bind(entityType, propertyInfo.PropertyType, propertyInfo.GetSimpleMemberName()));
            }
        }
        private void Process(IConventionEntityTypeBuilder entityTypeBuilder)
        {
            var entityType = entityTypeBuilder.Metadata;
            var model      = entityType.Model;

            foreach (var propertyInfo in entityType.GetRuntimeProperties().Values)
            {
                if (!entityTypeBuilder.CanHaveServiceProperty(propertyInfo))
                {
                    continue;
                }

                var factory = Dependencies.MemberClassifier.FindServicePropertyCandidateBindingFactory(propertyInfo, model);
                if (factory == null)
                {
                    continue;
                }

                entityTypeBuilder.ServiceProperty(propertyInfo)?.HasParameterBinding(
                    (ServiceParameterBinding)factory.Bind(entityType, propertyInfo.PropertyType, propertyInfo.GetSimpleMemberName()));
            }
        }