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

后端 未结 6 1489
感动是毒
感动是毒 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:29

    Entity Framework does not supply hooks to change the way it composes SQL statements, so you can't tell it to fetch and Trim string fields from the database.

    It would be possible to trim string properties in the ObjectContext.ObjectMaterialized event, but I think this would greatly affect performance. Also, it would take a lot of if-else or switch code to do this for specific properties (as you intend to do). But it could be worth a try if you want to do this for nearly all properties (except the keys, for instance).

    Otherwise I would go for the additional properties.

提交回复
热议问题