Select in two tables

0
Ban.cs
public partial class Ban
    {
        public int IdBan { get; set; }
        public System.DateTime DataBan { get; set; }
        public System.DateTime DataDesban { get; set; }
        public int Usuario_IdUsuario { get; set; }
        public string Motivo { get; set; }

        public virtual Usuario Usuario { get; set; }
    }


Usuario.cs
public partial class Usuario
    {
        public Usuario()
        {
            this.Avaliacao = new HashSet<Avaliacao>();
            this.Ban = new HashSet<Ban>();
            this.Comentario = new HashSet<Comentario>();
            this.Denuncia = new HashSet<Denuncia>();
            this.Login = new HashSet<Login>();
            this.Mensagens = new HashSet<Mensagens>();
            this.Mensagens1 = new HashSet<Mensagens>();
            this.Pedido = new HashSet<Pedido>();
            this.Publicacao = new HashSet<Publicacao>();
            this.UsuarioPermissoes = new HashSet<UsuarioPermissoes>();
        }

        public int IdUsuario { get; set; }
        public string NomeCompleto { get; set; }
        public string Email { get; set; }
        public string Senha { get; set; }
        public string Sexo { get; set; }
        public string Telefone { get; set; }
        public string About { get; set; }
        public string Nickname { get; set; }
        public string Email2 { get; set; }
        public string Endereco { get; set; }
        public string Bairro { get; set; }
        public string Estado { get; set; }
        public string Cep { get; set; }
        public string Celular { get; set; }
        public string FotoPerfil { get; set; }
        public string StatusPerfil { get; set; }
        public Nullable<int> NBans { get; set; }
        public Nullable<bool> Banido { get; set; }
        public System.DateTime DtCadastro { get; set; }
        public System.DateTime DtNasc { get; set; }

        public virtual ICollection<Avaliacao> Avaliacao { get; set; }
        public virtual ICollection<Ban> Ban { get; set; }
        public virtual ICollection<Comentario> Comentario { get; set; }
        public virtual ICollection<Denuncia> Denuncia { get; set; }
        public virtual ICollection<Login> Login { get; set; }
        public virtual ICollection<Mensagens> Mensagens { get; set; }
        public virtual ICollection<Mensagens> Mensagens1 { get; set; }
        public virtual ICollection<Pedido> Pedido { get; set; }
        public virtual ICollection<Publicacao> Publicacao { get; set; }
        public virtual ICollection<UsuarioPermissoes> UsuarioPermissoes { get; set; }
    }

I have an action that returns a list of site bans. However, I do not want to return only the data from this table "Ban", I would like to also display the name of the User that was banned, to facilitate the identification of the users that have been banned. How do I display the user name along with the data in the "Ban" table?

    
asked by anonymous 02.11.2014 / 20:21

1 answer

1

There is no secret:

var ban = contexto.Bans.Include(b => b.Usuario).FirstOrDefault();
var nomeUsuario = ban.Usuario.Nome;
    
02.11.2014 / 23:00