Hello, I'm using NHibernate 1.2GA and I'm confronting with difficulty.
Here goes the situation:
I've the following model (resumed):
Code:
public class Lancamento //discriminator value 0
{
Int64 id;
Double valor;
Byte situacao;
DateTime vencimento;
Int32 numeroParcela;
Operacao operacao;
}
public class Recebimento : Lancamento //discriminator value 1
{
}
public class AReceber : Recebimento //discriminator value 3
{
}
public class Pagamento : Lancamento //discriminator value 2
{
}
public class APagar : Pagamento //discriminator value 4
{
}
public class Operacao //discriminator value 0
{
Int64 id;
Int64 codigoInterno;
String numeroDocumento;
String descricao;
DateTime data;
Double valor;
Byte situacao;
Int32 numeroTerminal;
String observacao;
IList lancamentos;
}
public class Receita : Operacao //discriminator value 1
{
}
public class Venda : Receita //discriminator value 4
{
}
public class Despesa : Operacao //discriminator value 2
{
}
public class Compra : Despesa //discriminator value 5
{
}
public class Baixa : Operacao //discriminator value 3
{
}
All classes and subclasses is mapped with the proxy attribute equally the attribute name in the class node (As I see in the section '15.1.3. Single-ended association proxies' in NHibernate Documentation) and lazy=true.
In theory the types Lancamento and Operacao is never used.
So when I query for class 'Lancamento', the property 'operacao' gives me a proxied instance of the classes (Eg.: CProxyType.....Venda or CProxyType.....Compra) inherited from class 'Operacao'.
Then when I try to ask (in C#) '(Lancamento.Operacao is Venda)', for a item wich 'obviously' is a Venda, it returns me 'false', because 'Lancamento.Operacao.GetType()' is equal to 'CProxyType.....Venda'. It is a subclass of 'Operacao' but not is a 'Venda'.
I found an alternative to this situation using NHibernate.NHibernateUtil.GetClass(), or make a join, but it cause slow down of performance or some pollution to my code, and I can't make a cast to correct type (Eg.: (Venda)Lancamento.operacao).
In really I want to make a suggestion:
It would be nice if there's an option to create the correct class when I access this property.
But if there's another way to automatically returns the correct type without use join or NHibernate.NHibernateUtil.GetClass(), please tell me.
Thanks everybody.
Alex