Return primary ID on object insert

Return primary ID on object insert

Postby XStranger » Wed 25 Mar 2015 14:02

Hi,

I want insert to table record, primary ID generate by trigger.
When read ID, I have "Parameter 'returnIdTask' not found".

Code: Select all
Task.Attach(EntityContext1);
Task.Name := 'TEST';
Task.Save;
Label1.Caption := IntToStr(Task.IdTask);

For field IdTask in model I set
Code: Select all
Auto-Sync = OnInsert
IdGenerator = Identity (Custom)


How I get primary ID generated by trigger?

Best regards, Alexander.
XStranger
 
Posts: 8
Joined: Wed 04 Mar 2015 13:55

Re: Return primary ID on object insert

Postby AlexP » Thu 26 Mar 2015 07:09

Hello,

Please specify the exact version of EntityDAC, IDE. In addition, specify the name of the DB and EntityProvider you are working with.
AlexP
Devart Team
 
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Return primary ID on object insert

Postby XStranger » Thu 26 Mar 2015 08:06

Hi,

I use:
1) UniDAC version 5.3.9 for Delphi XE3
2) EntityDAC version 1.2.4 for Delphi XE3

On form for connect I have components:
1) EntityConnection
2) EntityUniDACProvider
3) UniConnection
4) InterBaseUniProvider

In EntityConnection I set:
Provider = UniDAC
Dialect = InterBase
Connection string = 'Data Provider=UniDAC; SQL Dialect=InterBase; Login Promt=False; Server=192.168.1.1; database=BDRK; username=SYSDBA; password=masterkey'
XStranger
 
Posts: 8
Joined: Wed 04 Mar 2015 13:55

Re: Return primary ID on object insert

Postby AlexP » Thu 26 Mar 2015 09:47

Hello,

Thank you for the information. We have reproduced the described case and will investigate the reason for such behavior. We will inform you as soon as we have any results.
AlexP
Devart Team
 
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Return primary ID on object insert

Postby XStranger » Mon 30 Mar 2015 11:43

I used my code for MS SQL Server 2012 too.
Table structure is:
Code: Select all
CREATE TABLE ASRK_TEST.dbo.RK_TASK_1 (
  ID uniqueidentifier NOT NULL DEFAULT (NEWID()),
  Name varchar(50) NULL,
  CONSTRAINT PK_RK_TASK_1 PRIMARY KEY (ID)
) ON [PRIMARY]
GO

In model for field ID I set:
Code: Select all
Auto-Sync: OnInsert
Access: Public
Getter Access: Public
Setter Access: Public

My procedure is:
Code: Select all
procedure TForm1.Button5Click(Sender: TObject);
var Task: TRkTask1;
begin
  Task := EntityContext1.CreateEntity(TRkTask1) as TRkTask1;
  Task.Attach(EntityContext1);
  Task.Name := 'Test by Sany 2015-03-25:0005';
  Task.Save;
  Label1.Caption := GUIDToString(Task.Id);
end;

On run procedure I have: 'newid() is not valid GUID value.'
XStranger
 
Posts: 8
Joined: Wed 04 Mar 2015 13:55

Re: Return primary ID on object insert

Postby AlexP » Tue 31 Mar 2015 09:01

Hello,

Currently, the GUID data type is not supported for SDACDataProvider. We have already added support for the data type, this feature will be available in the next EntityDAC version.

P.S. The definition of such field in EntityDeveloper must look like the following:

Code: Select all
Auto-Sync: Always
Entity Key: True
Name: Id
Server Data Type: UNIQUEIDENTIFIER NOT NULL
Source: ID
Type: Guid
AlexP
Devart Team
 
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Return primary ID on object insert

Postby XStranger » Wed 01 Apr 2015 10:48

I like use for connect - UniDAC, because I make program worked with FireBird and MS SQL Server. PostgreSQL in future.
XStranger
 
Posts: 8
Joined: Wed 04 Mar 2015 13:55

Re: Return primary ID on object insert

Postby AlexP » Wed 01 Apr 2015 11:30

This feature will be supported by all the providers that work with MS SQL Server (SDAC, UniDAC, ADO, FireDAC, etc.)
AlexP
Devart Team
 
Posts: 5530
Joined: Tue 10 Aug 2010 11:35


Return to EntityDAC