Hello, My Session Object looks like below -
public class Session
{
public int Id { get; set; }
public int StudentId { get; set; }
public string? SessionDetails { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public int Valid { get; set; }
}
I wish to create a POST that will create an instance of session with StartTime as systemdate (EF: Add). After session is over I would call the EF : Update call to store the EndTime.
Question: Is there any way to get the system generated Id in response when I Add the instance? That way I can keep the Id and then use it to Update.
Anandu G NathPosted Dec 29, 2023, 3:50 AM
Check Below Code for yor refrences
Sachin SinghPosted Mar 14, 2023, 8:08 AM
follow this
At session start
on session end
Naimish MakwanaPosted Mar 14, 2023, 3:48 AM
Hello Dave,
Try below code :
the
SaveChangesAsyncmethod is called after adding the new session instance to the database. This method will update theIdproperty of the session instance with the system-generated Id.Thanks
Naimish Makwana