I am trying to retrieve all entities of type Queried
from the database where Referenced
property or it's ancestor for which its label (meaning referenced.Parent.ChildLabel) is equal to some given label value exampleLabel
, has an Id
equal to exampleId
.
I tried using:
var result = nhibernateSession
.Query<Queried>()
.Where(queried => queried.SelfReferencing.GetSelfOrAncestor("exampleLabel") == exampleId)
.ToList();
but it throws a "System.NotSupportedException", probably because it does not know how to translate the GetSelfOrAncestor
into SQL.
The method GetSelfOrAncestor(string label)
returns the Id
of the SelfReferencing
instance on which it was called or it's ancestor which meets the condition that this.Parent.ChildLabel
is equal to exampleLabel
, otherwise returns 0.
For example, in the following diagram if queried.SelfReferencing
would point to the one at Level 2
, GetSelfOrAncestor("exampleLabel")
would return the Id
of the object at Level 1
.
public class Queried
{
public int Id { get; set; }
public SelfReferencing Referenced { get; set; }
}
public class SelfReferencing
{
public SelfReferencing Parent { get; set; }
private IList<SelfReferencing > children = new List<SelfReferencing >();
public virtual IList<SelfReferencing > Children
{
get
{
return children;
}
set
{
children = value;
}
}
public string ChildLabel { get; set; }
}
Any help on how to achieve this would be highly appreciated :)