Utilizing NHibernate I am attempting to use a lambda expression to retrieve objects based on the status and values between a parent child relationship. AbstractWorkflowRequestInformation has a collection of WorkflowRequestInformationAction. Each of the two classes have their own Status properties. To illustrate here are the abbreviated classes as they relate to this query:
public class AbstractWorkflowRequestInformation
{
public virtual RequestStatus RequestStatus { get; set; }
public virtual IEnumerable<WorkflowRequestInformationAction>
WorkflowRequestInformationActionList { get; set; }
}
public class WorkflowRequestInformationAction
{
public virtual ActionStatus Status { get; set; }
public virtual string RoleIdentifier { get; set; }
public virtual string RoleName { get; set; }
}
Given this relationship I want to retrieve AbstractWorkflowRequestInformation objects based on a List<KeyValuePair<string, string>> called roles. I realize that the exception is being caused by a lack of parsing of the Any(...) extension method, but I am unsure of alternative queries. Thus far all permutations on the below query have caused the same or similar exceptions:
public IEnumerable<IRequestInformation> GetRequestsPendingActionBy(
List<KeyValuePair<string, string>> roles)
{
var results = GetSession().Query<AbstractWorkflowRequestInformation>()
.Where(r => r.RequestStatus == RequestStatus.Pending
&& r.WorkflowRequestInformationActionList
.Any(a => ActionStatus.Pending == a.Status
&& roles.Any(kp => kp.Key == a.RoleName
&& kp.Value == a.RoleIdentifier)))
.ToList();
return results;
}
The ultimate goal is to retrieve only those AbstractWorkflowRequestInformation objects which are pending and have a pending WorkflowRequestInformationAction matching a KeyValuePair in the roles enumerable.
I am not wedded to using a lambda expression as this expression has already grown unwieldy, if there’s a more elegant ICriteria expression I am all ears. What are my options to restrict my results based upon the values in my roles List<KeyValuePair<string, string>> but prevent the “Specified method is not supported” exception?
I think this would get same results…
You could probably take a similar approach with NH Linq. I’m more comfortable with QueryOver/Criteria though.