0

I have a ChatSequence entity with a DateTimeCreated property that's a DateTime. But when I try and set it, I get an exception that's saying nullreferenceexception

I'm setting it like this

ChatSequence newSequence = new ChatSequence();
sequence.DateTimeCreated = DateTime.UtcNow;

and here is the object

public class ChatSequence
{
    [Key]
    public int ChatSequenceId { get; set; }

    public int TotalMessages { get; set; }

    [Index]
    public int ToYogaProfileRefId { get; set; }
    [ForeignKey("ToYogaProfileRefId")]
    public virtual YogaProfile ToProfile { get; set; }

    //[Index]
    //public int FromId { get; set; }
    [Index]
    public int FromYogaProfileRefId { get; set; }
    [ForeignKey("FromYogaProfileRefId")]
    public virtual YogaProfile FromProfile { get; set; }


    [Index]
    public DateTime LastMessageSent { get; set; }

    [Index]
    public int PartitionId { get; set; }

    public DateTime DateTimeCreated { get; set; }
}
chuckd
  • 13,460
  • 29
  • 152
  • 331

1 Answers1

2

There is a mistake in your code. You have created an object with the different name and setting value on different..

ChatSequence newSequence = new ChatSequence();
sequence.DateTimeCreated = DateTime.UtcNow;

Try this ..

ChatSequence newSequence = new ChatSequence();
newSequence.DateTimeCreated = DateTime.UtcNow;
Muhammad Saqlain
  • 2,112
  • 4
  • 33
  • 48