0

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;
    }
Mohamed Ahmed Sayed
  • 115
  • 1
  • 1
  • 11

1 Answers1

1

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;
}
Karan
  • 10,338
  • 3
  • 20
  • 35
  • fine it solves the error but gives me another error Message = "The entity or complex type 'project.model' cannot be constructed in a LINQ to Entities query." – Mohamed Ahmed Sayed Aug 29 '18 at 11:26
  • Please check this question. I hope it will help. https://stackoverflow.com/a/12532338/9695286 – Karan Aug 29 '18 at 11:37