-2

I'm trying to convert this SQL query to LINQ but the most I can get is joining the tables. After that I can't figure out the syntax for the WHERE part or how to return it as a list (ToList()).

var groups = db.ENG_Hazmanifest.SqlQuery("SELECT ENG_Hazmanifest.*, 
ENG_Locations.sitenumb FROM ENG_Hazmanifest INNER JOIN ENG_Locations ON 
ENG_Hazmanifest.site = ENG_Locations.id WHERE ENG_Hazmanifest.display = '1' 
ORDER BY ENG_Hazmanifest.pudate").ToList();

As far as I've gotten is:

var groups = from ENG_Hazmanifest in db.ENG_Hazmanifest 
                          join ENG_Locations in db.ENGI_Locations
                          on ENG_Hazmanifest.site equals ENG_Locations.id

What do I need to add to this to?

Rafe
  • 7,036
  • 5
  • 24
  • 27
  • And you can add `where ENG_Hazmanifest.display = '1'` _before_ the `join` (and of course an appropriate `select` at the end taking the values you need). – René Vogt Jul 15 '19 at 16:55
  • I don't get how I'm supposed to add the select part. – Rafe Jul 15 '19 at 17:01
  • 1
    Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) might help you? – NetMage Jul 15 '19 at 19:28

1 Answers1

1

Figured it out.

var groups = from ENG_Hazmanifest in db.ENG_Hazmanifest
                          where ENG_Hazmanifest.display == '1'
                          join ENG_Locations in db.ENGI_Locations
                          on ENG_Hazmanifest.site equals ENG_Locations.id select ENG_Hazmanifest;
Rafe
  • 7,036
  • 5
  • 24
  • 27