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
Post a Comment