cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List' asp.net-web-api entity-framework-6

Question

I want to retrieve all determined columns from the model table as queryable I write code blow it shows me

Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List'

any help to solve this error with the best practice:**

public IQueryable<DAL.model> GetAllmodels()
    {
        var models = (from d in db.models
                      where (d.Model_Deleted == false)
                      select (
                      new
                      {
                          d.Model_ID,
                          d.Model_Name,
                          d.Model_Image

                      })).AsQueryable();

        return models;
    }
1
0
8/29/2018 11:04:39 AM

Accepted Answer

Instead of selecting anonymous object with new { .. } Try as below with new DAL.model() { ... }.

public IQueryable<DAL.model> GetAllmodels()
{
    var models = (from d in db.models
                  where (d.Model_Deleted == false)
                  select (
                  new DAL.model()
                  {
                      Model_ID = d.Model_ID,
                      Model_Name = d.Model_Name,
                      Model_Image = d.Model_Image
                  })).AsQueryable();

    return models;
}
1
8/29/2018 11:11:38 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow