Skip to content

Commit

Permalink
FbValueGeneratorSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Dec 10, 2024
1 parent 80f25c7 commit d8f0069
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,62 @@ public FbValueGeneratorSelector(ValueGeneratorSelectorDependencies dependencies,

public new virtual IFbValueGeneratorCache Cache => (IFbValueGeneratorCache)base.Cache;

[Obsolete("Use TrySelect and throw if needed when the generator is not found.")]
public override ValueGenerator Select(IProperty property, ITypeBase entityType)
{
if (TrySelect(property, entityType, out var generator))
{
return generator;
}

throw new ArgumentException(
CoreStrings.InvalidValueGeneratorFactoryProperty(
nameof(FbSequenceValueGeneratorFactory), property.Name, property.DeclaringType.DisplayName()));
}

public override bool TrySelect(IProperty property, ITypeBase entityType, out ValueGenerator valueGenerator)
{
if (property.GetValueGeneratorFactory() != null
|| property.GetValueGenerationStrategy() != FbValueGenerationStrategy.HiLo)
{
return base.Select(property, entityType);
return base.TrySelect(property, entityType, out valueGenerator);
}

var propertyType = property.ClrType.UnwrapNullableType().UnwrapEnumType();

var generator = _sequenceFactory.TryCreate(
valueGenerator = _sequenceFactory.TryCreate(
property,
propertyType,
Cache.GetOrAddSequenceState(property, _connection),
_connection,
_rawSqlCommandBuilder,
_commandLogger);

if (generator != null)
if (valueGenerator != null)
{
return generator;
return true;
}

var converter = property.GetTypeMapping().Converter;
if (converter != null
&& converter.ProviderClrType != propertyType)
{
generator = _sequenceFactory.TryCreate(
valueGenerator = _sequenceFactory.TryCreate(
property,
converter.ProviderClrType,
Cache.GetOrAddSequenceState(property, _connection),
_connection,
_rawSqlCommandBuilder,
_commandLogger);

if (generator != null)
if (valueGenerator != null)
{
return generator.WithConverter(converter);
valueGenerator = valueGenerator.WithConverter(converter);
return true;
}
}

throw new ArgumentException(
CoreStrings.InvalidValueGeneratorFactoryProperty(
nameof(FbSequenceValueGeneratorFactory), property.Name, property.DeclaringType.DisplayName()));
return false;
}

protected override ValueGenerator FindForType(IProperty property, ITypeBase entityType, Type clrType)
Expand Down

0 comments on commit d8f0069

Please sign in to comment.