Reputation: 3
I would like to select one image from products images when i call products list. I could not use two where and function in row. my database structure is like below:
Products: ID Name
Images: ID Name Status ProductID
I need only images which has true status.
my function for getting products is same below: (incomplete)
Public Function GetProducts() As List(Of LeannModel.Product)
Dim xList As New List(Of LeannModel.Product)
Using context As New LeannEntities
xList = (From w In context.Products.Include("Image").Where(Function(i) i.Images.Where(Function(u) u.ImageBase = True)) Select w).ToList
End Using
Return xList
End Function
Upvotes: 0
Views: 568
Reputation: 364279
You cannot use condition on included data. Include always loads all related entities so in your case you can try to revert the query. Query images with condition and include product (where you don't have any condition). Once you have data in the application you can call ToList
and transform result set to have product with image instead of image with product.
Upvotes: 2