I wrote such class:
class Test
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public List<String> Strings { get; set; }
public Test()
{
Strings = new List<string>
{
"test",
"test2",
"test3",
"test4"
};
}
}
and
internal class DataContext : DbContext
{
public DbSet<Test> Tests { get; set; }
}
After run code:
var db = new DataContext();
db.Tests.Add(new Test());
db.SaveChanges();
my data is getting saved but just the Id
. I don't have any tables nor relationships applying to Strings list.
What am I doing wrong? I tried also to make Strings virtual
but it didn't change anything.
Thank you for your help.
Test
entity. So make a new entity withId
property andMyString
property, then make a list of that. – Simplehearted