Is there a way to define eager loading per entire data context, so I could state something like this -- "when using this data context when loading Customer always load associated City as well"?
So, something very similar to Options and LoadWith in Linq to Sql.
No Entity framework doesn't offer equivalent to DataLoadOptions available in Linq-to-Sql. There is no way to define something like LoadWith or AssociateWith globally.
Like Ladislav said, there currently is no way to do this in EF. However, the question comes back to why you want to do this globally rather than on a per-query basis.
If your main purpose is to abstract away eager loading out of your business layer, one options is to do something like I describe on in a blog post I wrote here. Essentially it describes a library that I want to create (time permitting) where it automatically determines how to eager load by looking at the data structure a query should be based around.
However, I don't know if that would solve the core issue of what you are trying to do or not without more detail of why you want this globally
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With