コード例 #1
0
        public SlimProperty(
            string name,
            Type clrType,
            PropertyInfo?propertyInfo,
            FieldInfo?fieldInfo,
            SlimEntityType declaringEntityType,
            PropertyAccessMode propertyAccessMode,
            bool nullable,
            bool concurrencyToken,
            ValueGenerated valueGenerated,
            PropertySaveBehavior beforeSaveBehavior,
            PropertySaveBehavior afterSaveBehavior,
            int?maxLength,
            bool?unicode,
            int?precision,
            int?scale,
            Type?providerClrType,
            Func <IProperty, IEntityType, ValueGenerator>?valueGeneratorFactory,
            ValueConverter?valueConverter,
            ValueComparer?valueComparer,
            ValueComparer?keyValueComparer,
            CoreTypeMapping?typeMapping)
            : base(name, propertyInfo, fieldInfo, propertyAccessMode)
        {
            DeclaringEntityType    = declaringEntityType;
            ClrType                = clrType;
            _isNullable            = nullable;
            _isConcurrencyToken    = concurrencyToken;
            _valueGenerated        = valueGenerated;
            _beforeSaveBehavior    = beforeSaveBehavior;
            _afterSaveBehavior     = afterSaveBehavior;
            _valueGeneratorFactory = valueGeneratorFactory;
            _valueConverter        = valueConverter;

            if (maxLength != null)
            {
                SetAnnotation(CoreAnnotationNames.MaxLength, maxLength);
            }
            if (unicode != null)
            {
                SetAnnotation(CoreAnnotationNames.Unicode, unicode);
            }
            if (precision != null)
            {
                SetAnnotation(CoreAnnotationNames.Precision, precision);
            }
            if (scale != null)
            {
                SetAnnotation(CoreAnnotationNames.Scale, scale);
            }
            if (providerClrType != null)
            {
                SetAnnotation(CoreAnnotationNames.ProviderClrType, providerClrType);
            }

            _typeMapping      = typeMapping;
            _valueComparer    = valueComparer ?? TypeMapping.Comparer;
            _keyValueComparer = keyValueComparer ?? TypeMapping.KeyComparer;
        }
コード例 #2
0
        private static ValueDirection GetValudDirection(IProperty property, PropertySaveBehavior saveBehavior, ValueGenerated generatorFlag)
        {
            if (saveBehavior != PropertySaveBehavior.Save || (property.IsPrimaryKey() && property.ValueGenerated.HasFlag(generatorFlag)))
            {
                return(ValueDirection.Read);
            }
            else
            {
                var result = ValueDirection.Write;
                if (property.ValueGenerated.HasFlag(generatorFlag))
                {
                    result = result | ValueDirection.Read;
                }

                return(result);
            }
        }
コード例 #3
0
        /// <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>
        public static string CheckAfterSaveBehavior([NotNull] this IProperty property, PropertySaveBehavior behavior)
        {
            if (behavior != PropertySaveBehavior.Throw &&
                property.IsKey())
            {
                return(CoreStrings.KeyPropertyMustBeReadOnly(property.Name, property.DeclaringEntityType.DisplayName()));
            }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Finds the property named <paramref name="propertyName"/> on all entities and sets its saving behavior to <paramref name="saveBehavior"/>
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="propertyName"></param>
        /// <param name="saveBehavior"></param>
        /// <returns></returns>
        public static ModelBuilder SetPropertySaveBehavior(this ModelBuilder builder, string propertyName, PropertySaveBehavior saveBehavior)
        {
            var properties = builder.Model
                             .GetEntityTypes()
                             .SelectMany(entityType => entityType.GetProperties())
                             .Where(p => p.Name == propertyName);

            foreach (var property in properties)
            {
                property.SetAfterSaveBehavior(PropertySaveBehavior.Ignore);
            }

            return(builder);
        }