How to get new record id on save

Posts   
 
    
Gianc1412
User
Posts: 40
Joined: 30-Oct-2007
# Posted on: 30-Nov-2007 15:03:36   

I have something like the following currently being used:


ProductEntity product = new ProductEntity();

product.price = productprice;
product.name = productname;

product.Save();

But i need to get the new productid (PK) when the record is created returned immediately following the save method. Is this possiable?

For example I would like do do something like the following:

I have something like the following currently being used:


ProductEntity product = new ProductEntity();

product.id = productid;
product.name = productname;

int newProductId = product.Save();

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Nov-2007 15:34:23   

If you are using an identity field for the PK, it would be automaicatlly returned for you in the corresponding property inside the entity.

ProductEntity product = new ProductEntity();

product.price = productprice;
product.name = productname;

product.Save();

int newId = product.Id;
Gianc1412
User
Posts: 40
Joined: 30-Oct-2007
# Posted on: 30-Nov-2007 16:05:37   

thanks