I am trying to Data seed for my database as I build out my controller. Currently Date is set as public DateTime. I'm not sure how to enter the data type so I can existing data to test my search query.
class System.String Represents text as a sequence of UTF-16 code units.
Cannot implicitly convert type 'string' to 'System.DateTime' [MessageBoard]csharp(CS0029)
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Message>()
.HasData(
new Message { MessageId = 1, Description = "This is a test message", Group = "TEST", Date = "19//03//2013T18:06", Author = "Mark" },
new Message { MessageId = 2, Description = "This is a test message", Group = "TEST 1", Date = "2022-01-01T10:10:10", Author = "Mark" },
new Message { MessageId = 3, Description = "This is a test message", Group = "TEST", Date = "2022-01-01T10:10:10", Author = "Mark" },
new Message { MessageId = 4, Description = "This is a test message", Group = "TEST 1", Date = "2022-01-01T10:10:10", Author = "Jack" },
new Message { MessageId = 5, Description = "This is a test message", Group = "Test", Date = "2022-01-01T10:10:10", Author = "Jack" }
);
}
CodePudding user response:
I just need to parse it!
Date = DateTime.Parse("2022-01-01,"),