Getting PK value during commit

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-May-2011 06:35:08   

LLBLGEN 3.1 Rel date 20-May-2011 Framework .NET 2.0 Oracle 9i MSORACLE

I am trying to get the PK value after commit.

Problem is, I am using for loop to insert multiple records, and then UOW to commit. So on commit, i need to get all the PK values inserted into entity.

for (int i = 0; i < dgridnewrecord.Rows.Count - 1; i++) { var eventmember = new EventpassEntity(); eventmember.Billdate = dateevent.Value;

}


eventmemberuow.AddForSave(eventmember);



eventmemberuow.Commit(adaptereventmember, true);

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-May-2011 10:33:31   

Out of the Box.

Please check each entity after calling Commit, you should find the PK fields already have their values set.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-May-2011 10:35:05   

Walaa wrote:

Out of the Box.

Please check each entity after calling Commit, you should find the PK fields already have their values set.

I do understand this. But my problem is I am inserting multiple entries and committing at once. Say I insert 5 times, i need to get 5 PK's at once after I commit

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-May-2011 10:54:33   

Do you mean, the problem is how to access the entities that have been saved?

If so, you can add entities to a collection, add the collection the UoW, using AddCollectionForSave().

Then after the commit these entities should have their PKs set.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-May-2011 10:55:47   

Walaa wrote:

Do you mean, the problem is how to access the entities that have been saved?

If so, you can add entities to a collection, add the collection the UoW, using AddCollectionForSave().

Then after the commit these entities should have their PKs set.

Actually I am using for loop for single entity. then when it commits it only gives me last saved PK.

"add entities to a collection, add the collection the UoW, " Will this resolve the problem ? if yes How do I do this walaa any example codes on forum some where?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-May-2011 11:08:26   

The problem in your code is that you add to the UoW outside the For Loop, and thus only the last entity would be added to the UoW. You should move this line inside the For Loop.

Anyway here is the collection example.

var collection = new EntityCollection<EventpassEntity>();

for (int i = 0; i < dgridnewrecord.Rows.Count - 1; i++)
{
                    var eventmember = new EventpassEntity();
                    eventmember.Billdate = dateevent.Value;

                    collection.Add(eventmember);
}

eventmemberuow.AddCollectionForSave(collection);
eventmemberuow.Commit(adaptereventmember, true); 
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-May-2011 11:09:15   

Walaa wrote:

The problem in your code is that you add to the UoW outside the For Loop, and thus only the last entity would be added to the UoW. You should move this line inside the For Loop.

Anyway here is the collection example.

var collection = new EntityCollection<EventpassEntity>();

for (int i = 0; i < dgridnewrecord.Rows.Count - 1; i++)
{
                    var eventmember = new EventpassEntity();
                    eventmember.Billdate = dateevent.Value;

                    collection.Add(eventmember);
}

eventmemberuow.AddCollectionForSave(collection);
eventmemberuow.Commit(adaptereventmember, true); 

Let me try and revert back by evening

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-May-2011 11:54:40   

shekar wrote:

Walaa wrote:

The problem in your code is that you add to the UoW outside the For Loop, and thus only the last entity would be added to the UoW. You should move this line inside the For Loop.

Anyway here is the collection example.

var collection = new EntityCollection<EventpassEntity>();

for (int i = 0; i < dgridnewrecord.Rows.Count - 1; i++)
{
                    var eventmember = new EventpassEntity();
                    eventmember.Billdate = dateevent.Value;

                    collection.Add(eventmember);
}

eventmemberuow.AddCollectionForSave(collection);
eventmemberuow.Commit(adaptereventmember, true); 

Let me try and revert back by evening

Thanks walaa collection works fine