How can I configure Entity Framework to automatically trim values retrieved for specific columns mapped to char(N) fields?

后端 未结 6 1488
感动是毒
感动是毒 2020-12-02 14:30

I\'m working with a third-party database in which all text values are stored as char(n). Some of these text values are primary keys, whereas others are just nor

6条回答
  •  不知归路
    2020-12-02 15:09

    If you are using Entity Framework Core, you can use Conversion like this:

    entity.Property(e => e.Name)
                 .HasConversion(
                    new ValueConverter(v => v.TrimEnd(), v => v.TrimEnd()));
    

提交回复
热议问题