Enumeration yielded no results in WEB API

753 Views Asked by At

I have a simple code.

    public IHttpActionResult Get()
    {
        using (var db = new AppDBContext())
        {
            var task = (from act in db.Activities select act);
            return Ok(task.ToList());
        }
    }

When I am debugging I am getting Enumeration yielded no results but there is 200 records when i execute it in database.

1

There are 1 best solutions below

0
On

I was doing silly mistake.

My wrong code

    public AppDBContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
        Configuration.ProxyCreationEnabled = false;
        Configuration.LazyLoadingEnabled = false;
    }

I thought DefaultConnection is a connection string. but when i changed it to my databasename TaskFiveDB4 every thing is fine now.

Correct code

    public AppDBContext()
        : base("TaskFiveDB4", throwIfV1Schema: false)
    {
        Configuration.ProxyCreationEnabled = false;
        Configuration.LazyLoadingEnabled = false;
    }