Last post Jan 03, 2021 06:32 PM by DA924
Dec 31, 2020 07:03 PM|kobruleht|LINK
ASP.NET MVC Core 5 application uses Npgsql Entity Framework Core Data Provider to get data from Postgres database using Entity Framework Core. Columns in database are defined as CHAR(n) type, like
create table prpalk (
Column types cannot changed to varchar.
Using EF commands like string nimi = ctx.Prpalks.Single().Sfirmanimi; to get data, strings in application contain also trailing spaces. How to remove trailing spaces automatically ?
Is there some event in EF Core which can used to trim all string columns when returned to application ?
I havent found such setting in EF data provider, Npgsql or Postgres database.
Column types cannot changed to varchar type due to compatibility with existing legacy application.
Jan 01, 2021 06:02 PM|DA924|LINK
You can't do the above?
Jan 01, 2021 08:46 PM|kobruleht|LINK
Properties are used hundreds of places in code. Some methods returns list of objects. Sometimes property names are not hard-coded.
Object can contain references to related objects which can also contain triling spaces.
Trimming trailing spaces in all those cases this requires creating routine which walks over object trees and trims spaces from string properties. This is lot of work.
Jan 03, 2021 06:32 PM|DA924|LINK
There is nothing I know about from a ORM, EF, standpoint that can do what you are seeking. The key would be to address whatever code that is persisting the data and trim it before it is saved.