AureliusDataSet - Testing an EntityField to be null?

I have a TTransaction class which has a TAureliusEntityField Invoice of type TInvoice. Using a TAureliusDataSet (adsTransaction), I am trying to determine whether the Transaction is linked to an Invoice (updating TActionList). I have tried:

MyAction.Enabled := adsTransactionInvoice.IsNull;
MyAction.Enabled := adsTransaction.FieldByName('Invoice').IsNull;
MyAction.Enabled := adsTransaction.EntityFieldByName('Invoice').IsNull;

Neither of the above statement works - FALSE is returned at all times.
However, what does work correctly is:

MyAction.Enabled := (adsTransactionInvoice.AsObject = nil);

What's the explanation for this? Am I doing something wrong or IsNull just not meant to be used with a TAureliusEntityField? If so, why is IsNull implemented then?

TAureliusEntityField doesn't override default RTL TField.GetIsNull, so, from a pure TField's point of view, there's something there - it's not null.

I use this way:
if Assigned(adsEnderecosBairro.AsObject) then ...
in your case,
MyAction.Enabled := Assigned(adsTransactionInvoice.AsObject);

Could be an interesting feature request. Maybe like:

function GetIsNull : Boolean; override;


function TAureliusEntityField.GetIsNull : Boolean;
  Result := not Assigned(AsObject);

sorry ... should be:
MyAction.Enabled := not Assigned(adsTransactionInvoice.AsObject);

That depends what the action does. It may create the Object (in which case it should not be assigned yet) or it may edit the Object (in which case it should be assigned already) :wink:

Concerning you're earlier analysis (well explained :+1:t2:): don't you agree that this actually is a bug? From a programmer's perspective, all these calls should give the same result. A such, I would say it doesn't require a feature request but rather a bug report...

:smiley: It's an ancient discussion...
IsNull vs IsEmpty

There are other TField variants where IsNull is false, but the value might/should/could be considered empty.

In this case, the entity field is not (TObject speaking) null when you don't override GetIsNull - but it's empty. If you take Delphi help, IsNull should tell if the field has a value - so, for us, an entity field is useless if it doesn't have a value, then maybe it should return True.

Some also would say that if it was really null, we shouldn't be able to invoke "AsObject". :face_with_spiral_eyes:

At the end, it's just a matter of choosing an implementation and naming (IsNull,IsEmpty,IsNullOrEmpty), document it, and go on.