Last active
February 11, 2019 17:40
-
-
Save alexsandro-xpt/f07423a49c652e050baf00bc8a7190ae to your computer and use it in GitHub Desktop.
EF Value Conversions
This file contains hidden or 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
| // Mais detalhes em https://docs.microsoft.com/pt-br/ef/core/modeling/value-conversions | |
| private static readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings { NullValueHandling= NullValueHandling.Ignore }; | |
| public class UserPermissionConfiguration: IEntityTypeConfiguration<UserPermission> | |
| { | |
| public void Configure(EntityTypeBuilder<UserPermission> builder) | |
| { | |
| builder.ToTable("UserPermission"); | |
| builder.Property(b => b.Panes) | |
| .HasConversion( | |
| v => JsonConvert.SerializeObject(v, _jsonSettings), | |
| v => JsonConvert.DeserializeObject<IEnumerable<string>>(v)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment