Dave Bell

Dave Bell

  • NA
  • 108
  • 8.9k

Store Sessions using C# and EF

Mar 13 2023 11:19 PM

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.


Answers (3)