0

I get an error when I try to run the following query in LINQ to Entities:

 var query = DBConn.myView
                            .Select(dm => new App.DTOs.MyDTO
                            {
                                ID = dm.ID,
                                Prop1 = dm.Prop1
                                ....
                            })
                            .Where(dm => dm.TypeID != 4); 

The Error message is:

LINQ expression node type 'TypeID' is not supported in LINQ to Entities

It fails on the .ToList() call:

private List<MyDTO> lstDTO;
lstDTO = query.ToList();

However, if I remove the .Where() from the query, it works. Is there any way to use the Where clause with this query?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Amc_rtty
  • 3,662
  • 11
  • 48
  • 73
  • Not sure if this question is similar: http://stackoverflow.com/questions/3392612/convert-datatable-to-ienumerablet – John Sep 24 '12 at 11:36

1 Answers1

5

You just need to swap your Select and Where part around:

var query = DBConn.myView
              .Where(dm => dm.TypeID != 4)
              .Select(dm => new App.DTOs.MyDTO
                            {
                                ID = dm.ID,
                                Prop1 = dm.Prop1
                                ....
                            });
Andrei
  • 55,890
  • 9
  • 87
  • 108
Jamiec
  • 133,658
  • 13
  • 134
  • 193