2
I cannot access the methods of a daughter class that was created using database first:
namespace Dados
{
using System;
using System.Collections.Generic;
public partial class pessoa
{
public pessoa()
{
this.pessoa_endereco = new HashSet<pessoa_endereco>();
}
public int id { get; set; }
public string tipo { get; set; }
public string razao_social { get; set; }
public string nome_fantasia { get; set; }
public string cpf_cnpj { get; set; }
public string rg_insc_estadual { get; set; }
public string insc_substituicao { get; set; }
public string insc_municipal { get; set; }
public Nullable<System.DateTime> data_expedicao_rg { get; set; }
public string orgao_expedidor_rg { get; set; }
public virtual administrador administrador { get; set; }
public virtual banco banco { get; set; }
public virtual cliente cliente { get; set; }
public virtual filial filial { get; set; }
public virtual fornecedor fornecedor { get; set; }
public virtual ICollection<pessoa_endereco> pessoa_endereco { get; set; }
public virtual usuario usuario { get; set; }
public virtual vendedor vendedor { get; set; }
}
}
the daughter class is:
namespace Dados
{
using System;
using System.Collections.Generic;
public partial class pessoa_endereco
{
public int id { get; set; }
public int pessoa_id { get; set; }
public string logradouro { get; set; }
public string numero { get; set; }
public string complemento { get; set; }
public string ponto_referencia { get; set; }
public string cep { get; set; }
public string bairro { get; set; }
public Nullable<int> cidade_id { get; set; }
public string nome_contato { get; set; }
public string telefone_1 { get; set; }
public string ramal_telefone_1 { get; set; }
public string telefone_2 { get; set; }
public string ramal_telefone_2 { get; set; }
public string celular { get; set; }
public string email { get; set; }
public virtual cidade cidade { get; set; }
public virtual pessoa pessoa { get; set; }
}
}
controller:
takeeatEntities context = new takeeatEntities();
var pessoas = context.pessoa
.GroupJoin(context.pessoa_endereco, p => p.id, a => a.pessoa_id, (p, a) => new { p, a })
.SelectMany(a => a.a.DefaultIfEmpty(), (p, a) => new PessoaDados
{
Id = p.p.id,
Razao_social = p.p.razao_social,
p.a. //não tem acesso aos metodos da pessoa_endereço
})
.ToList();
how can I access these methods in the controller, because when I put p.a. it does not bring any personal address field, if I do p. it brings me all fields only of the parent person class
I still can not access the properties of the personal class_address, but I noticed by chance that I can access all the virtual public that were declared, then include it in the list and appeared, for sure I’m not doing the right way, but the problem now is another. I saw that database-first despite all the branch that breaks is not the solution idelal, because if I change a field in the bank and give an update on Model.edmx it will erase everything I did, although I think code-first will give me a lot of work because I will no longer be able to touch the bank directly to make changes, it is the best solution!
– Gleyson Silva
But I marked your answer as correct because it gave me a light on what to do, thank you very much for your help!
– Gleyson Silva