Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Closed Unassigned: Include method uses inner join [1075]

$
0
0
Found a problem with the Include method when using nullable navigation properties. Used to work in EF5.

Example:

```
var cart = context.ShoppingCarts
//.Include(c => c.Items) //Works
//.Include(c => c.Items.Select(i => i.Order)) //Also still works
.Include(c => c.Items.Select(i => i.Order.Select(o => o.Status))); //Used to work in EF5
```
While the first 2 Includes would still work the last adds a inner join to the SQL query, probably since the Status for Order is not nullable. Therefore Items with Order == NULL are not included in the cart.


Example classes:

```
public class ShoppingCart {
public int Id { get; set; }
public virtual ICollection<Item> Items { get; set; }

...
}

public class Item {
public int Id { get; set; }
public int? OrderId { get; set; } //Nullable
public Order Order { get; set; }

...
}

public class Order {
public int Id { get; set; }
public int StatusId { get; set; } //Not nullable
public Status Status { get; set; }

...
}

public class Status {
public int Id { get; set; }

...
}
```
Comments: Dupe

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>