Working locally

The subject of this chapter is queries, but in a real application, you don’t just run queries for their own sake; you want to do something with the results. That’s not always as straightforward as it might appear, but the DbSet.Local property makes it simpler:

You can bind directly to the context (once you’ve loaded the data), but that presents some problems if you want to run additional queries, for example to allow your users to find a specific entity. The problem is that the EntitySet and DbSet are actually queries. Think about what happens if you execute code like this:

Image

Recipe theRecipe = (from r in context.Recipes         where ...

Get Fluent Entity Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.