예제 #1
0
        /// <summary>
        ///     <para>
        ///         Returns the <see cref="MySqlValueGenerationStrategy" /> to use for the property.
        ///     </para>
        ///     <para>
        ///         If no strategy is set for the property, then the strategy to use will be taken from the <see cref="IModel" />.
        ///     </para>
        /// </summary>
        /// <returns> The strategy, or <see cref="MySqlValueGenerationStrategy.None"/> if none was set. </returns>
        public static MySqlValueGenerationStrategy?GetValueGenerationStrategy([NotNull] this IReadOnlyProperty property, StoreObjectIdentifier storeObject = default)
        {
            var annotation = property[MySqlAnnotationNames.ValueGenerationStrategy];

            if (annotation != null)
            {
                return((MySqlValueGenerationStrategy?)annotation);
            }

            if (property.GetDefaultValue() != null || property.GetDefaultValueSql() != null || property.GetComputedColumnSql() != null)
            {
                return(null);
            }

            if (storeObject != default &&
                property.ValueGenerated == ValueGenerated.Never)
            {
                return(property.FindSharedStoreObjectRootProperty(storeObject)
                       ?.GetValueGenerationStrategy(storeObject));
            }

            if (IsCompatibleIdentityColumn(property) && property.ValueGenerated == ValueGenerated.OnAdd)
            {
                return(MySqlValueGenerationStrategy.IdentityColumn);
            }

            if (IsCompatibleComputedColumn(property) && property.ValueGenerated == ValueGenerated.OnAddOrUpdate)
            {
                return(MySqlValueGenerationStrategy.ComputedColumn);
            }

            return(null);
        }
예제 #2
0
            static bool IsStrategyNoneNeeded(IReadOnlyProperty property, StoreObjectIdentifier storeObject)
            {
                if (property.ValueGenerated == ValueGenerated.OnAdd &&
                    property.GetDefaultValue(storeObject) == null &&
                    property.GetDefaultValueSql(storeObject) == null &&
                    property.GetComputedColumnSql(storeObject) == null &&
                    property.DeclaringEntityType.Model.GetValueGenerationStrategy() != NpgsqlValueGenerationStrategy.None)
                {
                    var providerClrType = (property.GetValueConverter() ?? property.FindRelationalTypeMapping(storeObject)?.Converter)
                                          ?.ProviderClrType.UnwrapNullableType();

                    return(providerClrType != null && (providerClrType.IsInteger()));
                }

                return(false);
            }