1
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);
}
}
Personal
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);
}
}
Personal login
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");
}
}
This way both Personal and Personal Login gets Address. How to
that Personcustomer has Address and Personal Informationlogin?
Could take Address from Parent Person Class, and make the relationship between Address and Personcustomer only that I will fall into another problem of column duplicity because this Address Class, will also be using in Personcontact,Personprovide,Personprofile that inherits from Person.
I wanted to leave Address being a daughter of the Pessoa class.
when building Personcustomer call address list that is in Person
when it is Personal
when it is Personal to call the address list that is in Person
.... so will.
Can someone help me?
Yes, I think I can help you: Let go of these heritages, they will give you more work than solution. For example, instead of Personal login, create a class User and relate it to Person, no inheritance. Personal and Personal, but probably worth the same approach: distinct classes and relationships instead of inheritance.
– Caffé
Hello Caffé has how you explain to me how it would be?
– Daniel Machado