You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
May I offer an alternative?
Create a new partial class with your DbContext class and add this into it:
publicoverrideintSaveChanges(boolacceptAllChangesOnSuccess){UpdateEntityValues();returnbase.SaveChanges(acceptAllChangesOnSuccess);}publicoverrideTask<int>SaveChangesAsync(boolacceptAllChangesOnSuccess,CancellationTokencancellationToken=default){UpdateEntityValues();returnbase.SaveChangesAsync(acceptAllChangesOnSuccess,cancellationToken);}publicoverrideTask<int>SaveChangesAsync(CancellationTokencancellationToken=default){UpdateEntityValues();returnbase.SaveChangesAsync(cancellationToken);}privatevoidUpdateEntityValues(){foreach(varentityinChangeTracker.Entries()){foreach(varpropertyinentity.Properties){if(property.IsModified&&property.CurrentValue.GetType()==typeof(string)){// Trim happens hereproperty.CurrentValue=property.CurrentValue.Trim();}}}}
That works for mutations, but not querying. I'm using this to generate a model on a vendor database and they have the columns set to char instead of varchar.
Activity
Intecpsp commentedon Nov 7, 2019
I modified my context to add this to all columns, but then had them removed when a new table was added through the tool.
jespersh commentedon Nov 7, 2019
May I offer an alternative?
Create a new partial class with your DbContext class and add this into it:
Intecpsp commentedon Nov 7, 2019
That works for mutations, but not querying. I'm using this to generate a model on a vendor database and they have the columns set to char instead of varchar.
ErikEJ commentedon Nov 7, 2019
Just add a partial DbContext class, and implement the partial OnModelCreatingPartial method.
Maybe I should add this to the docs?
Intecpsp commentedon Nov 7, 2019
I like that approach! Doing it that way allows me to code the relationships that were missed to! Thanks!
ErikEJ commentedon Nov 10, 2019
Docs updated