Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

In my project I'm getting an empty array from database. I'm using SQL Server, WebAPI 2 and for the client side AngularJS to display the data from the database. I don't know what is wrong.

Here is the client side code:

$http.get('/api/group')
  .success(function (data, status) {
     $log.info('Data:', data);
     $log.info('Status:', status);
  })
  .error(function (data, status) {
     $log.info('Data:', data);
     $log.info('Status:', status);
  });

WebAPI Controller of group:

public class GroupController : ApiController
{
  public EtfContext db = new EtfContext();

  // GET api/group
  public IQueryable<Group> GetGroups()
  {
    //var groups = from g in db.QR_Groups
    //             select g;
    //return groups;
    return db.QR_Groups;
  }

The Model of group:

public class Group
{
    public Group()
    {
    }

    public int Id { get; set; }
    public string name { get; set; }
    public string code { get; set; }
}

And the DataContext for connecting to the database:

public class EfContext : DbContext
{
  public EfContext() 
    : base("name=EfContext")
    {
    }

  public DbSet<Group> QR_Groups { get; set; }
}

The Table in the database called "QR_Groups" with 3 columns: id, name, code. How do I get the data from the database?

share|improve this question
1  
Are there actual rows in the database? – Knelis Jun 29 '15 at 13:01
    
change it to return db.QR_Groups.ToList() and make sure you have data in your database. – dotctor Jun 29 '15 at 13:02
    
@Knelis Yes data is already in the database table. – yuro Jun 29 '15 at 13:04
    
@dotctor I'm using IQueryable. When I try to set ToList then I'm getting an error – yuro Jun 29 '15 at 13:05
    
Also change the return type of GetGroups to IEnumerable<Group> – dotctor Jun 29 '15 at 13:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.