Hi,
I'm new to Aurelius, when I try to read data from a field of type Proxy<TList<TMyClass>> I receive this error.
The class simplified:
type
[Entity]
[Table('Detail')]
[Sequence('SeqDetail')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Inheritance(TInheritanceStrategy.SingleTable)]
TDetail= class
private
[Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
FId: Integer;
[Column('Text', [TColumnProp.Required], 20)]
FText: String
public
property Text: String read FText;
end;
type
[Entity]
[Table('Main')]
[Sequence('SeqMain')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Inheritance(TInheritanceStrategy.SingleTable)]
TDetail= class
private
[Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
FId: Integer;
[ManyValuedAssociation([], CascadeTypeAll)]
[ForeignJoinColumn('MainID', [TColumnProp.Required])]
FItems: Proxy<TList<TDetail>>;
function GetItems: TList<TDetail>;
public
property Items: TList<TDetail> read GetItems;
end;
function TMain.GetItems: TList<TDetail>;
begin
if Not Assigned(FItems.Value) then
FItems.SetInitialValue(TList<TItems>.Create);
Result:=Fitems.Value;
end;
If I save Items, all goes ok,
when the GetItems method is called, "Field/Property is not a Proxy<T> type..." error is raised.
What I am doing wrong?
Thanks
Claudio
wlandgraf
(Wagner Landgraf)
April 28, 2014, 1:32pm
2
Hello,
sorry but that code doesn't make sense. There are two TDetail classes. In GetItems you are creating a TList<TItems> which has nothing to do with TList<TDetail> declared in FItems field. Are you sure this code compiles, or, if it's correctly pasted here, it's clear it should not work.
Sorry,
but trying to simplify the code I've made mistakes,
Here the code corrected.
I need a field on the main class that contains a Proxy<TList<TDetail>>
Thanks
type
[Entity]
[Table('Detail')]
[Sequence('SeqDetail')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Inheritance(TInheritanceStrategy.SingleTable)]
TDetail= class
private
[Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
FId: Integer;
[Column('Text', [TColumnProp.Required], 20)]
FText: String
public
property Text: String read FText;
end;
type
[Entity]
[Table('Main')]
[Sequence('SeqMain')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Inheritance(TInheritanceStrategy.SingleTable)]
TMain= class
private
[Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
FId: Integer;
[ManyValuedAssociation([], CascadeTypeAll)]
[ForeignJoinColumn('MainID', [TColumnProp.Required])]
FItems: Proxy<TList<TDetail>>;
function GetItems: TList<TDetail>;
public
property Items: TList<TDetail> read GetItems;
end;
function TMain.GetItems: TList<TDetail>;
begin
if Not Assigned(FItems.Value) then
FItems.SetInitialValue(TList<TDetail>.Create);
Result:=Fitems.Value;
end;
Some more informations:
while the application is running, if I save values in FItems, all goes ok, and I can read data (function GetItems is called correctly).
When I close application, once restarted, when GetItems is called the exception is raised on FItems.Value call.
wlandgraf
(Wagner Landgraf)
April 29, 2014, 7:42am
5
Your GetItems is not using the same code as stated in documentation. Have you tried using the exactly same code as provided in documentation? It doesn't use SetInitialValue in GetItems. Also, make sure you set the ManyValueAssociation attribute with the lazy flag.
I've created a new empty class following the code in the documentation and it works.
So now I will recheck all my code to understand where is the difference.
Solved.
In the detail class there was a field declared as lazy but not as proxy, so the error were here.