What is the easiest way to intercept and manipulate an entity within an entity?

In the technology stack, I have an SQL database that is first used in the Entity Framework v6.1.3 database to open it for the rest of the .Net application.

I am trying to manipulate an entity before returning it to higher levels of the application so that the data in certain properties is masked / scrambled. Doing the same in the database is not an option.

The application architecture is pushing me toward trying to implement it at the lowest possible level.

The lowest level for me is somewhere in the Entity Framework. I tried to simplify the approach of modifying getters in generated classes.

private string _columnX; public string ColumnX { get { if (x) { return "*"; } return _columnX; } set { _columnX = value; } 

This works for simple queries. However, as soon as the request becomes more complex, and I access this object using the navigation properties, EF does not seem to use this code and relies on some internally generated magic.

I found some information about IDbCommandInterceptor, but I'm not sure if I can use it for my script and how to manipulate returned objects with it. Can I access an object in IDbCommandInterceptor in Entity Framework .

Question: Is there any intermediate level between EF and my database or some configuration in EF that would allow us to manipulate data in essence for each case when this data is requested?

UPDATE I used the proposed approach using ObjectMaterialized . The problem with forecasts indicated in the answer / comment remains. As discussed in another question, if forecasts are used, this approach does not work.

Is there a way to force forecasts to be manipulated so that the data in this column can be manipulated?

+5
source share

All Articles