Finding id of inserted record in formview bound to LLBLGenProDataSource

Posts   
 
    
like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 09-Apr-2008 09:39:54   

I have a formview bound to an LLBLGenProDataSource. This LLBLGenProDataSource is attached to an oracle table whose primary key is filled from a sequence. How can I get at the PK of the record that has just been inserted?

I've looked into

 Private Sub fvProjects_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles fvProjects.ItemInserted

    Debug.Print(e.Values("ProjectId"))

  End Sub

But this just returns "". I can read the .Values for all fields other than the PK.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Apr-2008 10:25:17   
like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 09-Apr-2008 14:51:03   

Thanks for your quick reply. I understand the concept of setting IsIdentity and have done this - the llblgen generated code is grabbing the next value for the primary key from the oracle sequence and using it when the new record is created.

I use a trigger like this so that llblgen can set the pk, but if I want to load records from oracle directly I can do so:


CREATE OR REPLACE TRIGGER PRR.PROJECT_PK_TIB
BEFORE INSERT
ON PRR.PROJECT REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN 
--Assign PK 
IF (:new.project_id IS NULL) THEN 
  SELECT seq_project.NEXTVAL INTO  
  :NEW.project_id FROM DUAL; 
END IF; 

END;
/

However, what I need to do is to get the primary key for the "just inserted" record, so that I can redirect away from the form to show the "just inserted" record.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Apr-2008 15:25:06   

If I understand you correctly, the the answer is the following:

In wrote:

If you have to use the trigger, please add this line to the appSettings of the config file of your app: <add key="OracleTriggerSequences" value="true"/>

(this is also documented in 'application configuration through config files' in the documentation )

like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 10-Apr-2008 08:49:27   

I don't think I have explained my question very well. To clarify: I have a asp.net formview (in insert mode) which I use to create a new entry in my oracle table and it works.

I would now like to find out the primary key of the newly created record as it is inserted so that I can redirect to another asp.net page showing as summary of the record that has just been added.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 10-Apr-2008 11:27:45   

Alright then please handle the LLBLGenProDataSource EntityInserted event, which is raised when LivePersistence is set to true and an entity was inserted successfully. The inserted entity is part of the event args.

like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 14-Apr-2008 16:00:00   

Spot on. Exactly what I wanted. Many thanks. For other's reference here is the code I ended up with...

 Private Sub dsProjects_EntityInserted(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.DataSourceActionEventArgs) Handles dsProjects.EntityInserted

    ' Show the newly entered project.
    Dim newProject As ProjectEntity = e.InvolvedEntity
    Response.Redirect(String.Format("Proj.aspx?ProjectId={0}", newProject.ProjectId))

  End Sub

It took me a while to find as it is a new feature added in v2.5 and I was still using v2.0. It was just the prompt I needed to upgrade, and the upgrade went seamlessly. Thanks again Walaa