Hi,
I am using EF4 and MVC 2.
I am inserting a new record to the database, and I need it to return the new ID value.
My stored procedure ends like this:
SELECT SCOPE_IDENTITY() AS NewApplicationID;
Here is my action method:
public ActionResult CreateApplication(ApplicationViewModel applicationViewModel)
{
if (ModelState.IsValid)
{
try
{
Mapper.CreateMap<ApplicationViewModel, Application>();
var application = (Application)Mapper.Map(applicationViewModel, typeof(ApplicationViewModel), typeof(Application));
var success = applicationRepository.InsertApplication(application);
}
catch (Exception ex)
{
}
}
return View("CreateApplication", applicationViewModel);
}
Here is my InsertApplication method in my repository class:
public int InsertApplication(Application application)
{
db.Applications.AddObject(application);
return db.SaveChanges();
}
I need to return the value of the new ID.
I hope someone can help.
Thanks.