Starting from EF Core 2.1, storing a string array becomes possible thanks to the support for value conversions
Here is our Entity:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyEntity | |
{ | |
public Guid Id{get;set;} | |
public string[] Strings { get; set; } | |
} |
And here is the code we added in the OnModelCreating():
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modelBuilder.Entity<MyEntity>() | |
.Id(e=> e.Id) | |
.Property(e => e.Strings) | |
.HasConversion( | |
v => string.Join(',', v), | |
v => v.Split(',', StringSplitOptions.RemoveEmptyEntries)); |