When you are writing this:
context.LettingProjects.Where(query).Select(s => s.Call).ToList();
EF will simply query for a single table.
However, as you probably configured the relationships in your models to contain other Tables too (
ICollection<EntityA>), they will contain a
null value because EF will not send a query asking for their data.
My question is, how does this even work? I don't know how EF handles this in the background, and it seems like a gotcha waiting to happen.
The answer to your question now should be simple:
when you write
.Include(s => s.OtherTable) you are asking EF to join your current table data with the one you specified.
EF will use the Foreign Key relationships and will give you back a collection of items with the data for the related tables, too (not null version). That's why it will not fail.
This is very similar to using the LINQ to Entities
Join method, but in this case, it's requiring you to write much less code unless you want to control the join operation by yourself.
- updating data in many-to-many relationship in entity framework in code first existing database
- Entity Framework infers relationship
- how to select data by linq in many-to-many relationship in First code Entity framework 5
- Entity Framework Code First Select Item Based on Relationship
- Entity Framework Core: many-to-many relationship with same entity
- Entity Framework 6 Code First Custom Functions
- Entity Framework - querying a many-to-many relationship table
- Entity Framework - An item with the same key has already been added. - Error when trying to define foreign key relationship
- Avoiding repeated projection code in Entity Framework
- Forcing Entity Framework to not generate NCLOB's when building Linq-to-Sql Code (Model First)
- Entity Framework Code First without app.config
- How to query many-to-many relationship with 'AND' condition using LINQ and Entity Framework
- Force inner join with many-to-many relationship entity framework
- Query a many to many relationship with Entity Framework and .NET 3.5
- Entity Framework Code First using context in Controller
- many to many mapping in entity framework code first
- How to Create a Run-Time Computed (NotMapped) Value in Entity Framework Code First
- Entity Framework Code First String Comparison with Oracle Db
- SQL subquery result in LINQ and Entity Framework Code First
- Entity Framework foreign key relationship returns no data
- most efficient Entity Framework Code First method of flattening / projecting parent entity with specific child
- Entity Framework Code First - Get blog posts which have certain tags
- Counting in a Many-To-Many Relationship in Entity Framework
- How to Query Icollections of Entity Framework Code First Data
- Entity Framework code first - Many to Many - Include conditional
- C# Entity Framework Core: how do I get the relationship of the bill to the vendor without including the vendor's list of bills?
- LINQ Entity Framework Select into a non-primary-key relationship
- Entity Framework Code First ToList method timing out on SQL Azure
- Entity Framework Insert In Code
- How to make a property unique in Entity Framework Code First
- Linq average of list with all its nested list values
- Linq to Entities Join, Group, Sum with Northwind Orders
- C# - Return record which has the lowest PayDate but also the highest ReconciliationDate
- NHibernate 3.0 IQueryable selecting ghost column
- Hierarchical object retrieve childsIds with linq
- LINQ select property by name
- How to map complex linq to object
- c# linq query extract repeating data types
- getting first element from nhibernate fetch collection
- EF5 Select objects based on child collection content
- ASP.NET MVC LINQ GroupBy differs from SQL Server GroupBy?
- Linq query taking too long to process results
- Linq query multiple tables with different attributes
- c# linq nested "conditional/composite" grouping
- How can I find the book with the highest price written after 2000?
- Parameterless aggregate operator 'Max' is not supported over projections
- use linq to group by and then run select query with where condition
- GroupBy Linq IEnumerable error
- LINQ OrderBy different field type depending on IF statement
- Calling ToList() on ConcurrentDictionary<TKey, TValue> while adding items