I have a Client class like that:
public class Client
{
public Person Pers { get; set; }
}
And I have 2 Person´s child class :
public class PersonType1 : Person
{
protected string att1;
protected string att2;
}
public class PersonType2 : Person
{
protected string att3;
protected string att4;
}
public class Person
{
protected string attx;
protected string atty;
}
So, my Client could be PersonType1 or PersonType2...
I need execute a Client search ... The parameters to that search are att1,att2,att3,att4,attx,atty... But all those are optional...
I´m trying to execute that search with ICriteria, but I dont know how specify that inheritance scheme...
You really cannot do this because at the criteria level the Person class is agnostic of any derived classes. The result set will be an
IList<Person>
even though iterating through the collection will show you that the elements will also comprise of PersonType1 and PersonType2 types (assume that we just fetch the whole set from the DB without any restrictions).That said, you can achieve the desired effect with a workaround: Define each derived type as a new subquery
for N derived types and then on your main Criteria query just do
alternatively, an ISQLQuery has not such limitations.
EDIT i'm adding below the necessary adjustments to find Client i will re-write the criteria to be a
<Client>
criteria and express the subquery restriction on the joined<Person>s
.