Hi,
I have a simple table (DemoTable) with fields ID and ParentID. ID is autoinc PK, and ParentID is FK with ID from the same table. Posting fails when I assign a value to ParentID with the error : (500) "Expected BeginObject but was Int64 at path $.ParentID"
Here is a more detaild description:
Table definition from db:
CREATE TABLE dbo.DemoTable (
ID Int IDENTITY NOT NULL,
ParentID Int,
Name NVarChar(50),
CONSTRAINT PK_DemoTable PRIMARY KEY CLUSTERED (ID)
)
GO
ALTER TABLE dbo.DemoTable WITH NOCHECK ADD CONSTRAINT FK_DemoTable_DemoTable FOREIGN KEY (ParentID)
REFERENCES dbo.DemoTable (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
GO
In Aurelius:
[Entity]
[Table('DemoTable')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TDemoTable = class
private
[Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FID: Integer;
[Column('Name', [], 50)]
FName: Nullable<string>;
[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ParentID', [], 'ID')]
FParentID: Proxy<TDemoTable>;
function GetParentID: TDemoTable;
procedure SetParentID(const Value: TDemoTable);
public
property ID: Integer read FID write FID;
property Name: Nullable read FName write FName;
property ParentID: TDemoTable read GetParentID write SetParentID;
end;
Test scenario using Swagger:
Post without assigning ParentID, body ->
{
"Name": "Name001"
}
Response Ok, body ->
{
"$id": 1,
"ID": 1,
"Name": "Name001",
"ParentID": null
}
Post again without ParentID body ->
{
"Name": "Name002"
}
Response Ok, body ->
{
"$id": 1,
"ID": 2,
"Name": "Name002",
"ParentID": null
}
All ok, and I have 2 records in db, one with ID=1 and one with ID=2.
Now, do a post with ParentID assigned. body ->
{
"Name": "FirstChild",
"ParentID": 1
}
...and Error 500: "Internal Server Serror" with this body:
{
"error": {
"code": "InvalidStateException",
"message": "Expected BeginObject but was Int64 at path $.ParentID"
}
Am I doing something wrong here, or maybe I'm overlooking something?
Any advice on how to solve this is greatly appreciated.