Poorly worded title, I know.
I have an object User
that has an property (a list of objects) (ICollection<Alert>) Alerts
. I want to order the alerts by the Alert's property (DateTime) LastActivatedDt
I tried (within a method w/ a parameter of int id
):
user = users
.Include(user => user.Alerts.OrderBy(alert => alert.LastActivatedDt)
.FirstOrDefault(user => user.Id === id)
But I get the following error:
System.InvalidOperationException: The Include property lambda expression 'user => {from Alert alert in user.Alerts orderby [alert].LastActivatedDt asc select [alert]}' is invalid. The expression should represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, E.g. '(Derived d) => d.MyProperty'.