Retrieving the record identity value after insert new record

Posts   
 
    
RamiMoj
User
Posts: 3
Joined: 21-Feb-2019
# Posted on: 21-Feb-2019 08:58:21   

Dear All; After Greeting... I have problem when I try to get the entity's identity field value after saving the new one ("Specified cast is not valid" message is appear). I am using oracle data base, and the entity 's identity field((primary key of table) is joined to some sequence item. Please, help to to solve this issue asap (see attachment file to more explaining).

My Code:

DeletingRequestEntity deletingRequest= new DeletingRequestEntity(); deletingRequest.DeletingRequestTypeId = deletingRequest.DeletingRequestTypeId; deletingRequest.DeletingRequestStatusId = deletingRequest.DeletingRequestStatusId; deletingRequest.CaseId = deletingRequest.CaseId; deletingRequest.DeletedRecordId = deletingRequest.DeletedRecordId; deletingRequest.DeletingReason = deletingRequest.DeletingReason; deletingRequest.RequestDate = DateTime.Now; if (deletingRequest.Save()) { int delRequestId = Convert.ToInt32(deletingRequest.DeletingRequestId); }

Thank You

Best Regards;

Attachments
Filename File size Added on Approval
Error.jpg 315,222 21-Feb-2019 08:58.34 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-Feb-2019 10:38:11   
Frans Bouma | Lead developer LLBLGen Pro
RamiMoj
User
Posts: 3
Joined: 21-Feb-2019
# Posted on: 21-Feb-2019 11:01:56   
  • LLBLGen Pro V5.1 (5.1.1) RTM
  • .Net framework 4.5
  • Oracle 12 g
Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 22-Feb-2019 02:19:05   

What's the DB Type and the mapped .NET type of that PK?

P.S. What is the following code doing?

deletingRequest.DeletingRequestTypeId = deletingRequest.DeletingRequestTypeId;
deletingRequest.DeletingRequestStatusId = deletingRequest.DeletingRequestStatusId;
deletingRequest.CaseId = deletingRequest.CaseId;
deletingRequest.DeletedRecordId = deletingRequest.DeletedRecordId;
deletingRequest.DeletingReason = deletingRequest.DeletingReason;
RamiMoj
User
Posts: 3
Joined: 21-Feb-2019
# Posted on: 24-Feb-2019 07:12:40   
  • DB is oracle 12g
  • Type of PK is number (decimal)
  • This is a simplify to my code: DeletingRequestEntity deletingRequest = new DeletingRequestEntity();
    deletingRequest.DeletingReason = "Test"; if (deletingRequest.Save()) { int delRequestId = Convert.ToInt32(deletingRequest.DeletingRequestId); // Incremental primary key }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Feb-2019 06:17:38   

RamiMoj wrote:

DeletingRequestEntity deletingRequest= new DeletingRequestEntity();
deletingRequest.DeletingRequestTypeId = deletingRequest.DeletingRequestTypeId;
deletingRequest.DeletingRequestStatusId = deletingRequest.DeletingRequestStatusId;
deletingRequest.CaseId = deletingRequest.CaseId;
deletingRequest.DeletedRecordId = deletingRequest.DeletedRecordId;
deletingRequest.DeletingReason = deletingRequest.DeletingReason;
deletingRequest.RequestDate = DateTime.Now;

Above code is weird. You are assigning an object's property to the same value's property...

deletingRequest.DeletingRequestTypeId = deletingRequest.DeletingRequestTypeId;

So please double check that.

About your second example. Does it work?

DeletingRequestEntity deletingRequest = new DeletingRequestEntity(); 
deletingRequest.DeletingReason = "Test";
if (deletingRequest.Save())
{                   
     int delRequestId = Convert.ToInt32(deletingRequest.DeletingRequestId); // Incremental primary key
}

If it doesn't work please double check that: - The sequence is mapped in your entity's mapping. The sequence should be selected in the sequence's combos, if it doesn't, do it yourself manually. ref...

David Elizondo | LLBLGen Support Team