This is a migrated thread and some comments may be shown as answers.

How to get the identity column after insert data

3 Answers 114 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Byland
Top achievements
Rank 1
Byland asked on 05 Dec 2011, 08:35 AM
Hi, All

I saw the old ORM API, I can get the identity data from database:
 
scope.Transaction.Begin();

Customer c = new Customer();
c.Name =
 "Smith";
c.CustomerNo = 34567;
scope.Add( c );
// during the Add() call, an object identifier
// is assigned to the new Customer object
IObjectId id = scope.GetObjectId( c );
scope.Transaction.Commit();

But how can i do like this using the new ORM API

context.get.....???????

Any one can give me some suggestion?

Thanks a lot!!!

Byland

3 Answers, 1 is accepted

Sort by
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 05 Dec 2011, 09:28 AM
Hi Byland,

Just right after the context.Add method you can do a context.GetScope().Transaction.Flush()

It will execute all server side calculated Ids and populate those Ids to your objects, so you can read it from there by doing a customer.Id for example.

Regards

Henrik
0
Byland
Top achievements
Rank 1
answered on 05 Dec 2011, 09:56 AM
Hi, Henrik

A lot of thx!!!!!!
0
IT-Als
Top achievements
Rank 1
answered on 05 Dec 2011, 02:33 PM
Hi Byland,

You're welcome. If it helped you, it might help others, too. So please mark the answer as the solution to your question. It will help others find a solution more quickly. Thanks

Regards
Henrik
Tags
General Discussions
Asked by
Byland
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Byland
Top achievements
Rank 1
Share this question
or