ID Problem (EIdNotSetException)

Aurelius 5.13.0.0
XData 5.10.0.0.
Delphi 10.4

I get an exception (EIdNotSetException) when trying to list values from a very simple entity.

To me, it looks very much like this one:

In my situation I have:

Table ELFFrequency:

CREATE TABLE dbo.ELFFrequency (
    ID Int NOT NULL,
    Name NVarChar(10) NOT NULL,
    Description NVarChar(50), 
    CONSTRAINT PK_ELFFrequency PRIMARY KEY CLUSTERED (
      ID
    )
)
GO

Data in table:
image

Model:

  [Entity]
  [Table('ELFFrequency')]
  [Id('FID', TIdGenerator.None)]
  TELFFrequency = class
  private
    [Column('ID', [TColumnProp.Required])]
    FID: Integer;
    
    [Column('Name', [TColumnProp.Required], 10)]
    FName: string;
    
    [Column('Description', [], 50)]
    FDescription: Nullable<string>;
  public
    property ID: Integer read FID write FID;
    property Name: string read FName write FName;
    property Description: Nullable<string> read FDescription write FDescription;
  end;

Code that raises exception:

function TServices.GetELFFrequency: TList<TELFFrequency>;
begin
  // LEO 06.02.2023: Test to raise exception
  Result := TXDataOperationContext.Current.GetManager.Find<TELFFrequency>.List;
end;

The exception I get is: ".....raised exception class EIdNotSetException with message 'Id not set on entity of class TELFFrequency.'."

Is this a bug or am I maybe overlooking something here?

Thank you,
Leif Eirik

Id = 0 ist not allowed, I think.

You are totally right it seems! Thank you for sharing, much appreciated.

Changed my data to not use ID = 0 and all is fine.

There is also the option to use IdUnsavedValue if having id=0 in database is absolutely necessary:

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.