Reputation: 14540
No sure why I'm getting this error running this query below
Unable to create a constant value of type 'YogaBandy2017.Models.Profile.YogaProfile'. Only primitive types or enumeration types are supported in this context.
var requestedEvents = dbContext.YogaSpaceEvents
.Where(i => i.RequestedInstructor == yogaProfile)
.OrderByDescending(i => i.EventDateTime)
.Select(i => new PendingEvent
{
SpaceName = i.YogaSpace.Overview.Title,
SpaceImage = i.YogaSpace.YogaSpaceImages
.Where(j => j.IsMainImage)
.Select(j => j.ImageThumbnailCropped11)
.FirstOrDefault(),
SpaceId = i.YogaSpace.YogaSpaceId,
SpaceEventsHosted = i.YogaSpace.ClassesHosted,
SpaceReviewNumber = i.YogaSpace.ReviewNumber,
SpaceReviewPercent = i.YogaSpace.ReviewPercentage,
SpaceNumberOfReviews = i.YogaSpace.NumberOfReviews,
HostImage = i.YogaSpace.YogaProfile.YogaProfileImages
.Where(k => k.IsMainImage)
.Select(k => k.ImageThumbnailCropped)
.FirstOrDefault(),
HostId = i.YogaSpace.YogaProfile.YogaProfileId,
HostName = i.YogaSpace.YogaProfile.FirstName,
EventDateTime = i.EventDateTime,
Style = i.StyleMain.ToString(),
Duration = i.Duration,
EventId = i.YogaSpaceEventId
})
.ToList();
Upvotes: 0
Views: 123
Reputation: 81493
You cant use Entities like that in an Where
clause (it has no idea how to convert it to SQL)
However, most likely they will have an Id
property. So you should be able to do the following
dbContext.YogaSpaceEvents.Where(i => i.RequestedInstructor.Id == yogaProfile.Id)
Upvotes: 5