c# - ASP.NET repository get id after insert -


how can id after insert() command. here code.

private readonly irepository<shoppingcart> _shoppingcartrepository; public shoppingcartbl(irepository<shoppingcart> shoppingcartrepository)     {         _shoppingcartrepository = shoppingcartrepository;     }  public int createnewshoppingcart(shoppingcart item)     {         if(item==null)             throw new argumentnullexception("shoppingcart variable");          this._shoppingcartrepository.insert(item);         return this._shoppingcartrepository.table.last().id;     } 

this part gives error: return this._shoppingcartrepository.table.last().id;

i need id of inserted item.

thanx

after have inserted entity should updated property maps primary key in database has new pk value.

like in case item.id give new id


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -