I am converting from one ORM to another (LLBGen Pro to Entity Framework). In order to properly refactor I need to understand something. In LLBGen Pro there's a concept called prefetch paths. Prefetch paths exists in order to reduce the number of queries required in cases where lazy loading negatively impacts performance. In Gen Pro, lets say I have 50 orders and I want to gather the customer related to each order. With lazy loading I could end up with 51 DB queries. 1 for the orders and 50 more for each customer due to the lazy loading of customers vs just 2 queries with prefetch paths enabled.
My understanding is that entity framework (or perhaps LINQ to SQL) generates the most optimum SQL for the situation. Is Entity Framework somehow smart enough to optimize the queries in such a case where LLB Gen Pro cannot? In other words, does entity framework generate the SQL at runtime intelligently where it can "look ahead" and see the need for all customers and generate a single query rather than 50 individual queries? Or, does EF support some type of "prefetch path" or does this require some advanced custom expression trees...etc?
The Entity Framework uses information in the model and mapping files to translate object queries against entity types represented in the conceptual model into data source-specific queries. Query results are materialized into objects that the Entity Framework manages.
The Entity Framework does not enforce any security permissions and will invoke any user-supplied data object code in process regardless of whether it is trusted or not. Ensure that authentication and authorization of the client is performed by the data store and by your application.
In the above code, you can see that Person is nested within the Student class. When you use the Entity Framework Power Tool to show how Entity Framework interprets the model this time, there's true Identity property, and Person complex type. So Entity Framework will persist that data.
The Entity Framework even supports mapping entities in the conceptual model to stored procedures in the data source. For more information, see CSDL, SSDL, and MSL Specifications. Object-oriented programming poses a challenge for interacting with data storage systems.
EF is not (yet) so smart.
I think you are looking for Include. This function allows you to eager load related entities.
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