Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

how to return id for newly created table in same method?

$
0
0

Hi, i have a controller that creates a table using EF with automated value for id.

var cust = new Cutomer
{
    Name = "James",
    Description = "Believs in ghosts"
}

_context.Customer.Add(cust);
await _context.SaveChangesAsync();

but i would like to return the created id value for this table so i could go on to the newly created page.

is this possible? Could i just return RedirectToAction(nameof(YourProfile), new { id = cust.Id} )

I can't test it where I am right now because I don't have windows and i don't know how to create db on mac.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>