Is there a way to convert projected enum-values to its enumeration?
I've found TMappingExplorer.DbValueToEnum, that would do this for me, but it's private...
this is the find I'm using:
[Enumeration(TEnumMappingType.emString, 'one,two')]
TEntityEnum = (teOne, teTwo);
TEntity = class
private
FEnum: TEntityEnum;
public
property Enum: TEntityEnum read FEnum write FEnum;
end;
// shortened Find:
hResult := ObjectManager.Find<TEntity>.
Select(TProjections.ProjectionList.Add(EntDic.Entity.Enum)).
Take(1).UniqueValue;
hResult.Values[0] = 'one' //or two, but I'd like to use teOne or teTwo...
wlandgraf
(Wagner Landgraf)
2
It is private indeed, but you can workaround it using a hack:
type
TInternalConverter = class(TLegacyDBValueConverter)
public
procedure DBToValue(const DBValue: Variant; var Value: TValue); reintroduce;
end;
{ TInternalConverter }
procedure TInternalConverter.DBToValue(const DBValue: Variant; var Value: TValue);
begin
inherited DBToValue(DBValue, Value);
end;
{ some code}
procedure TForm2.Button1Click(Sender: TObject);
var
Conv: TLegacyDBValueConverter;
Value: TValue;
Enum: TEntityEnum;
begin
Conv := Manager.Explorer.FindEntityTypeFromClass(TEntity).AllColumns.Find('Enum').Wrapper as TLegacyDBValueConverter;
TInternalConverter(Conv).DBToValue('two', Value);
Enum := Value.AsType<TEntityEnum>;
end;
This hack works, but could you just make TMappingExplorer.DbValueToEnum public?
Would be easier ;)
1 Like
wlandgraf
(Wagner Landgraf)
4
For now we are rather avoiding publishing too many methods in the explorer. We have a major refactor in sight.
Ok, maybe that's why there is no update since february?
wlandgraf
(Wagner Landgraf)
6
No, there is no relation.
system
(system)
Closed
7
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.