1

Is it possible to use an EF Core interceptor to influence the process of materialization when data from a database reader is converted into an object?

When not, it there another way to tell EF Core to use an instance of A1 instead of type A?

Regards, Torsten

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
zimmybln
  • 149
  • 3
  • 12
  • What is your purpose? Converting the query's result that the it A type, to A1 ? For example Convert from List to List ? – Ramil Aliyev 007 Feb 19 '21 at 05:07
  • Have you check this article? https://learn.microsoft.com/en-us/ef/core/logging-events-diagnostics/interceptors – nalnpir Feb 19 '21 at 05:09
  • We load data as instance of A as Dbmodel with DB definition purpose (i.e. Attributes for key, maxlength etc.). But the usage purpose has other needs, like INotifiyPropertyChanged or ObservableCollection within properties. So we copy the loaded instance of A to an another type A1. In theory it should be possible to model the entity A and load the entity A1 when they are identical, or identical properties or same structure. – zimmybln Feb 19 '21 at 05:14
  • Automapper and ProjectTo? – Svyatoslav Danyliv Feb 19 '21 at 06:17
  • Yes, Automapper is a good approach. But it is after the entity is loaded. We are looking something like DbSet.LoadAs(...) – zimmybln Feb 19 '21 at 08:54

1 Answers1

3

EF Core's team introduced in version 7 IMaterializationInterceptor which is exactly what you want to use.

You can find more information here. The API is quite simple.

However, the official documentation about interceptors does not mention (yet?) the existence of IMaterializationInterceptor.