protected virtual void ConfigureProperty(IMutableProperty property, string configuration, string value) { var propertyAnnotations = property.Oracle(); switch (configuration) { case nameof(RelationalPropertyAnnotations.DefaultValue): propertyAnnotations.DefaultValue = int.Parse(value); break; case nameof(RelationalPropertyAnnotations.DefaultValueSql): propertyAnnotations.DefaultValueSql = value; break; case nameof(RelationalPropertyAnnotations.ComputedColumnSql): propertyAnnotations.ComputedColumnSql = value; break; case nameof(OraclePropertyAnnotations.ValueGenerationStrategy): propertyAnnotations.ValueGenerationStrategy = OracleValueGenerationStrategy.IdentityColumn; break; default: throw new NotImplementedException(); } }
/// <summary> /// 将密钥属性配置为在以Oracle为目标时使用基于序列的hi-lo模式为新实体生成值。此方法将属性设置为 <see cref="ValueGenerated.OnAdd" />. /// </summary> /// <param name="propertyBuilder">正在配置的属性的创建器</param> /// <param name="name">序列的名称</param> /// <param name="schema">序列的方案</param> /// <returns> 同一个创建器实例,以便可以链接多个调用 </returns> public static PropertyBuilder ForOracleUseSequenceHiLo( [NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string name = null, [CanBeNull] string schema = null) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); IMutableProperty metadata = propertyBuilder.Metadata; name = name ?? OracleModelAnnotations.DefaultHiLoSequenceName; IMutableModel model = metadata.DeclaringEntityType.Model; if (model.Oracle().FindSequence(name, schema) == null) { model.Oracle().GetOrAddSequence(name, schema).IncrementBy = 10; } GetOracleInternalBuilder(propertyBuilder).ValueGenerationStrategy(OracleValueGenerationStrategy.SequenceHiLo); metadata.Oracle().HiLoSequenceName = name; return(propertyBuilder); }