0

I have 3 tables:

*USERS*
ID | USERNAME | ...

*SERVICE_NAME*
ID | SERVICE_NAME

*USER_SERVICES*
ID | ID_USER | ID_SERVICE

From the table *USER_SERVICES*, I can check if the user has the services enabled. This is my LINQ so far but it returns me only users who have actually at least one service enabled.

        var resultsServices = from p in USER_SERVICES
                      group p.ID_SERVICE by p.ID_USER into g
                      select new { ID_USER = g.Key, Services = g.ToList() };


        users = (from user in USERS
            join service in resultsServices on user.ID equals service.ID_USER
            where user.ID == service.ID_USER
            select new
            {
                user,
                service.Services
            });

How can I return all users, even if they do not have any service enabled that it "return null" or something?

DJack
  • 631
  • 1
  • 8
  • 34
  • Possible duplicate of [LEFT OUTER JOIN in LINQ](http://stackoverflow.com/questions/3404975/left-outer-join-in-linq) – Kaido Mar 02 '16 at 13:29
  • Apart from the clear duplication, you should **not** perform joins in LINQ. It's a clear sign that the classes are wrong. You should define relations between the entities so that the User class has a Services colletion with Service instances he has enabled. This would allow you to simply load the User and get all the related entities as well. No joins needed – Panagiotis Kanavos Mar 02 '16 at 13:33

0 Answers0