I’m trying to fetch first element from the collection like this
List<Entity> data = session.Query<Entity>()
.Fetch(x => x.Photos.First())
.ToList();
and I’m getting this error.
A fetch request must be a simple member access expression; ‘[100002]’ is a SubQueryExpression instead. Parameter name: relatedObjectSelector.
Now I’m using .Fetch(x => x.Photos.First()) cause I know that first element will always be populated, and it is. I do need just first element from the collection to reduce loading time, so this is exact solution I need, but I’m getting this error.
Fetch will fetch the entire collection, you can’t tell it to just fetch the first element using “fetch”, however you can probably get the desired effect using projections, or something like:
Although I’m not sure why you’d want a List instead of IList.. generally it’s preferable to use the interface