Question

I have a model that I want to load one of its columns from a source other than the database behind EF Core for example MongoDb.

The problem is that I can't figure how to override query execution in EF Core. For Saves it's OK because EF Core lets us to override SaveChanges and do our own logic.

For the read part, I decided to load the column lazily through its getter accessor. The goal is to have as little as possible change in our code (We have lots of projects that uses EF Core to load the object and I don't want to change code in a way that breaks all queries of that specific object).

But how to inject my MongoDb service to my model? For ASP.Net Core, we can create a custom model binder but for EF Core how to have a custom model binder or model creator to inject services to model? Can I use dependency injectors like Ninject or AutoFac (I just heard about them and don't have any experience with them)? Do they work with EF Core?

1
0
4/13/2020 1:58:10 PM

Popular Answer

You probably have to do the mapping in memory. I don't know if that is viable in your specific scenario. That means you would have to eagerload and then you could do mapping with auto mapper or another mapper. You would need an abstraction on top of ef where you could inject the mapping mechanism. The Ef core link provider would not be able to translate what you need to a SQL query.

0
4/14/2020 10:40:53 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow