I have the following model (simplified):
abstract class CartItem { EntityReference<Cart> Cart; }
class HotelCartItem : CartItem { EntityReference<Hotel> Hotel; }
class TransferCartItem : CartItem { }
class Hotel { }
As expressed “graphically”:
CartItem |<- HotelCartItem | |-> Hotel | |<- TransferCartItem
Now I want to load all CartItems and include data from the Hotel class if the type of CartItem is a HotelCartItem.
This is how I’m trying to do it, but it fails with a “does not declare a navigation property with the name ‘Hotel’.”
var q = from cartitems in context.CartItems
.Include("Hotel")
where cartitems.CART_ID == CartID
select cartitems;
If I leave out the .Include("Hotel") the Hotel property of CartItems of type Hotel is null.
My question:
Is there a way to get around this?
I ended up splitting the query into several parts:
Call it with:
3 . Add the CartItems to the collection of the Cart-object.