I have the following situation:
Person
public class Pessoa
{
public Pessoa()
{
Endereco = new List<Endereco>();
}
public virtual int IdPessoa { get; set; }
public virtual string Nome { get; set; }
public virtual IList<Endereco> Endereco { get; set; }
}
Map
public class PessoaMap: ClassMap<Pessoa>
{
public PessoaMap()
{
Id(x => x.IdPessoa);
Map(x => x.Nome)
.Not.Nullable()
.Length(MapLength.Texto);
HasMany<Endereco>(x => x.Endereco)
.KeyColumn("TipodePessoa")
.Cascade.All()
.Inverse();
Table("Pessoa");
}
Address
public class Endereco:Pessoa
{
public virtual string Numero { get; set; }
public virtual string Complemento { get; set; }
public virtual string CEP { get; set; }
public virtual string Cidade { get; set; }
public virtual string UF { get; set; }
public virtual string Pais { get; set; }
public virtual Pessoa Pessoa { get; set; }
}
Map
public class PessoaEnderecoMap : SubclassMap<PessoaEndereco>
{
public PessoaEnderecoMap()
{
Table(@"PessoaEndereco");
KeyColumn("IdPessoa");
Map(x => x.Numero)
.Not.Nullable()
.Length(MapLength.TextoCurto);
Map(x => x.Complemento)
.Not.Nullable()
.Length(MapLength.TextoCurto);
Map(x => x.CEP)
.Not.Nullable()
.Length(MapLength.TextoCurto);
Map(x => x.Cidade)
.Not.Nullable()
.Length(MapLength.TextoCurto);
Map(x => x.UF)
.Not.Nullable()
.Length(MapLength.TextoCurto);
Map(x => x.Pais)
.Not.Nullable()
.Length(MapLength.TextoCurto);
References(x => x.Pessoa);
}
}
CustomerCustom
public class PessoaCliente : Pessoa
{
public virtual string Cnpj { get; set; }
public virtual string InscrEstadual { get; set; }
public virtual string Telefone { get; set; }
}
Map
public class PessoaClienteMap : SubclassMap<PessoaCliente>
{
public PessoaClienteMap() {
Table(@"PessoaCliente");
KeyColumn("IdPessoa");
Map(x => x.Cnpj)
.Length(MapLength.TextoCurto);
Map(x => x.InscrEstadual)
.Length(MapLength.TextoCurto);
Map(x => x.Telefone)
.Length(MapLength.TextoCurto);
}
}
PersonLogin
public class PessoaLogin:Pessoa
{
public virtual string Senha { get; set; }
}
Map
public class PessoaLoginMap : SubclassMap<PessoaLogin>
{
public PessoaLoginMap()
{
KeyColumn("IdPessoa");
Map(x => x.Senha)
.Not.Nullable()
.Length(MapLength.TextoMini);
Table("PessoaLogin");
}
}
In this way, bothClient and PersonLogin are given Address. How do I
Does Customer have Address and PersonLogin data not?
I could take Address from the Person Parent Class, and do the relationship between Address and CustomerCustomer only that I will fall into another problem of double-column because this Address Class will be used also in PersonContact, PersonForm, PersonProfile that inherits from Person.
I wanted to leave Address being a child of the Person class.
When building CustomerClient call address list that is in Person
When PersonLogin does not call the Address List that is in Person
When PersonFornecer call the address list that is in Person
.... so it goes.
Can anyone help me?