Microsoft
Software
Hardware
Network
Question : Get identity of last insert (ASP.NET MVC Entity framework)
I am using ASP.NET MVC 2.0 with entity framework using MySQL as the database.
When I insert a new row into a table, is there a way to get the identity of the row just inserted?
In my repository, I have some code to insert a new row:
public void InsertNotice(Notice notice)
{
db.AddToNotices(notice);
}
At some point later, I save the changes with db.SaveChanges(), but I can't see how to get any information about the inserted row.
I hope that makes sense.
Answer : Get identity of last insert (ASP.NET MVC Entity framework)
I found the solution myself:
public int InsertNotice(Notice notice)
{
db.AddToNotices(notice);
db.SaveChanges();
return notice.NoticeID;
}
Thanks anyway.
Random Solutions
Why is this sql file not creating a mysql database as it should
Access to a server from a possibly unprotected computer
Can a C++ class declare instances of itself without having to use 'void *' ?
Metadata cleanup worked...too well (Active Directory disappeared)
Please help with Pig Latin translation
Vbscript to set focus when you only know part of a windows name
Cannot Install PEAR Packages
DatetimePicker Problem C#
ASP.net Missing something?!?!
Differences between full versions and "Click-to-Run" versions of MS Office