@amcorch In EF Core 2.1 a value converter can do this. Something like:
C#
modelBuilder
.Entity<Foo>()
.Property(e => e.Bar)
.HasConversion(v => v.Trim(), v => v.Trim());
This will remove any whitespace when coming out of or going into the database.
In EF Core 2.0 I don't think that there is an easy way to trim when data is coming from the database. You could override SaveChanges to trim going into the database.
Closing as duplicate of #242
Most helpful comment
@amcorch In EF Core 2.1 a value converter can do this. Something like:
C# modelBuilder .Entity<Foo>() .Property(e => e.Bar) .HasConversion(v => v.Trim(), v => v.Trim());This will remove any whitespace when coming out of or going into the database.
In EF Core 2.0 I don't think that there is an easy way to trim when data is coming from the database. You could override SaveChanges to trim going into the database.