/// <summary> /// Sets the <see cref="MySqlValueGenerationStrategy" /> to use for the property. /// </summary> /// <param name="property"> The property. </param> /// <param name="value"> The strategy to use. </param> public static void SetValueGenerationStrategy( [NotNull] this IMutableProperty property, MySqlValueGenerationStrategy?value) { CheckValueGenerationStrategy(property, value); property.SetOrRemoveAnnotation(MySqlAnnotationNames.ValueGenerationStrategy, value); }
protected virtual bool SetValueGenerationStrategy(MySqlValueGenerationStrategy?value) { if (value != null) { var propertyType = Property.ClrType; if (value == MySqlValueGenerationStrategy.IdentityColumn && !IsCompatibleIdentityColumn(propertyType)) { if (ShouldThrowOnInvalidConfiguration) { throw new ArgumentException( Property.Name + " " + Property.DeclaringEntityType.DisplayName() + " " + propertyType.ShortDisplayName()); } return(false); } } if (!CanSetValueGenerationStrategy(value)) { return(false); } if (!ShouldThrowOnConflict && ValueGenerationStrategy != value && value != null) { ClearAllServerGeneratedValues(); } return(Annotations.SetAnnotation(MySqlAnnotationNames.ValueGenerationStrategy, value)); }
/// <summary> /// Attempts to set the <see cref="MySqlValueGenerationStrategy" /> to use for properties /// of keys in the model that don't have a strategy explicitly set. /// </summary> /// <param name="model"> The model. </param> /// <param name="value"> The value to set. </param> /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param> public static MySqlValueGenerationStrategy?SetValueGenerationStrategy( [NotNull] this IConventionModel model, MySqlValueGenerationStrategy?value, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation(MySqlAnnotationNames.ValueGenerationStrategy, value, fromDataAnnotation); return(value); }
/// <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 new virtual bool ValueGenerationStrategy(MySqlValueGenerationStrategy?value) { if (!SetValueGenerationStrategy(value)) { return(false); } return(true); }
/// <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 new virtual bool ValueGenerationStrategy(MySqlValueGenerationStrategy?value) { if (!SetValueGenerationStrategy(value)) { return(false); } if (value == null) { HiLoSequenceName(null); HiLoSequenceSchema(null); } else if (value.Value == MySqlValueGenerationStrategy.IdentityColumn) { HiLoSequenceName(null); HiLoSequenceSchema(null); } return(true); }
public override InternalPropertyBuilder Apply(InternalPropertyBuilder propertyBuilder, DatabaseGeneratedAttribute attribute, MemberInfo clrMember) { MySqlValueGenerationStrategy?valueGenerationStrategy = null; ValueGenerated valueGenerated = ValueGenerated.Never; if (attribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Computed) { valueGenerated = ValueGenerated.OnAddOrUpdate; valueGenerationStrategy = MySqlValueGenerationStrategy.ComputedColumn; } else if (attribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity) { valueGenerated = ValueGenerated.OnAdd; valueGenerationStrategy = MySqlValueGenerationStrategy.IdentityColumn; } propertyBuilder.ValueGenerated(valueGenerated, ConfigurationSource.Convention); propertyBuilder.MySql(ConfigurationSource.DataAnnotation).ValueGenerationStrategy(valueGenerationStrategy); return(base.Apply(propertyBuilder, attribute, clrMember)); }
protected virtual bool CanSetValueGenerationStrategy(MySqlValueGenerationStrategy?value) { if (GetMySqlValueGenerationStrategy(fallbackToModel: false) == value) { return(true); } if (!Annotations.CanSetAnnotation(MySqlAnnotationNames.ValueGenerationStrategy, value)) { return(false); } if (ShouldThrowOnConflict) { if (GetDefaultValue(false) != null) { throw new InvalidOperationException( RelationalStrings.ConflictingColumnServerGeneration(nameof(ValueGenerationStrategy), Property.Name, nameof(DefaultValue))); } if (GetDefaultValueSql(false) != null) { throw new InvalidOperationException( RelationalStrings.ConflictingColumnServerGeneration(nameof(ValueGenerationStrategy), Property.Name, nameof(DefaultValueSql))); } if (GetComputedColumnSql(false) != null) { throw new InvalidOperationException( RelationalStrings.ConflictingColumnServerGeneration(nameof(ValueGenerationStrategy), Property.Name, nameof(ComputedColumnSql))); } } else if (value != null && (!CanSetDefaultValue(null) || !CanSetDefaultValueSql(null) || !CanSetComputedColumnSql(null))) { return(false); } return(true); }
private static void CheckValueGenerationStrategy(IProperty property, MySqlValueGenerationStrategy?value) { if (value != null) { var propertyType = property.ClrType; if (value == MySqlValueGenerationStrategy.IdentityColumn && !IsCompatibleIdentityColumn(property)) { throw new ArgumentException( MySqlStrings.IdentityBadType( property.Name, property.DeclaringEntityType.DisplayName(), propertyType.ShortDisplayName())); } if (value == MySqlValueGenerationStrategy.ComputedColumn && !IsCompatibleComputedColumn(property)) { throw new ArgumentException( MySqlStrings.ComputedBadType( property.Name, property.DeclaringEntityType.DisplayName(), propertyType.ShortDisplayName())); } } }
/// <summary> /// Attempts to set the <see cref="SqlServerValueGenerationStrategy" /> to use for properties /// of keys in the model that don't have a strategy explicitly set. /// </summary> /// <param name="model"> The model. </param> /// <param name="value"> The value to set. </param> public static void SetValueGenerationStrategy([NotNull] this IMutableModel model, MySqlValueGenerationStrategy?value) => model.SetOrRemoveAnnotation(MySqlAnnotationNames.ValueGenerationStrategy, value);
#pragma warning disable 109 /// <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 new virtual bool ValueGenerationStrategy(MySqlValueGenerationStrategy?value) => SetValueGenerationStrategy(value);
/// <summary> /// Sets the <see cref="MySqlValueGenerationStrategy" /> to use for the property. /// </summary> /// <param name="property"> The property. </param> /// <param name="value"> The strategy to use. </param> /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param> public static MySqlValueGenerationStrategy?SetValueGenerationStrategy([NotNull] this IConventionProperty property, MySqlValueGenerationStrategy?value, bool fromDataAnnotation = false) { CheckValueGenerationStrategy(property, value); property.SetOrRemoveAnnotation(MySqlAnnotationNames.ValueGenerationStrategy, value, fromDataAnnotation); return(value); }