0
My project has four classes:
public class Manifestacao
{
public long Id { get; set; }
public string NumeroChamado { get; set; }
public string DataHoraReg { get; set; }
public Cliente Cliente { get; set; }
public Usuario UsuarioRespReg { get; set; }
public List<Conteudo> Conteudos { get; set; }
}
public class Conteudo
{
public long Id { get; set; }
public string Categoria { get; set; }
public string SubCategoria { get; set; }
public string Descricao { get; set; }
public string DataHoraReg { get; set; }
public string Status { get; set; }
public long ManifestacaoId { get; set; }
public Manifestacao Manifestacao { get; set; }
}
public class Cliente
{
public long Id { get; set; }
public string Empresa { get; set; }
public string Contato { get; set; }
public string Email { get; set; }
public string Telefone { get; set; }
public string Ramal { get; set; }
public string Celular { get; set; }
}
public class Usuario
{
public long Id { get; set; }
public string Apelido { get; set; }
public string Nome { get; set; }
public string Categoria { get; set; }
public string Senha { get; set; }
public string Status { get; set; }
}
I need to fill out a datagridview with some database information that was persisted through the Entityframework: Content.Category, Content.Subcategory, Content.Description, Content.Status, Client.Company and User.Name
I disabled Lazyloading in the Context class:
public class EFContext : DbContext
{
public EFContext() : base("Pos_Venda_SAC")
{
this.Configuration.LazyLoadingEnabled = false;
Database.SetInitializer<EFContext>(
new DropCreateDatabaseIfModelChanges<EFContext>()
);
}
public DbSet<Cliente> Clientes { get; set; }
public DbSet<Conteudo> Conteudos { get; set; }
public DbSet<Manifestacao> Manifestacoes { get; set; }
public DbSet<Usuario> Usuarios { get; set; }
public DbSet<Destinatario> Destinatarios { get; set; }
}
Based on RU documentation in MSDN I tried to use the class below (Getconteudos()) to read the database, but in datagridview appear the columns with the names of the items of the Content class, but the information that should be associated with the other classes does not appear.
public IList<Conteudo> GetConteudos()
{
using (var context = new EFContext())
{
return context.Conteudos.Include(m => m.Manifestacao.Cliente).Include(u => u.Manifestacao.UsuarioRespReg.Nome).ToList();
}
}
There was something missing to configure?
How are you doing the Binding from the pro grid list?
– Jéf Bueno
You can and should do a Burst that extracts these columns, because datagridview does not work with complex data. Or create a viewmodel e.resolve this..
– novic
@LINQ dgvListage.Datasource = Getconteudos();
– Leandro