Popular a List with database data accessed by EntityFramework

0

How popular is my List in C #, with the data stored in the database accessed through EntityFramework?

Current code:

 public static IEnumerable<Contato> GetAll()
    {
        return new List<Contato> { //DAqui pa frente nao sei para onde ir . . .//
    
asked by anonymous 06.01.2015 / 14:10

1 answer

3

Consider that you already have your class that inherits from DbContext configured to work with the Entity Framework ... example:

public partial class SeuDBContext : DbContext
{
    ...     
    public DbSet<Contato> Contatos { get; set; }
    ...
}

In addition to your mapped entity, I believe that in the method itself you could do just that:

public IEnumerable<Contato> GetAll()
{
    using(var context = new SeuDBContext())
    { 
        return context.Contatos;
    }
}
    
06.01.2015 / 14:57