title: Linq left join with Entity Framework
body: <p>I have a table of Vehicles and I need to do a left join on VehicleAttribute.</p>
  
  <pre><code>var vehicle = (from v in context.Vehicles
                                 //join vehicleAttributes
                                 join va in context.VehicleAttributes on v.VehicleId equals va.VehicleId into vAttributes
                                 from vehicleAttributes in vAttributes.DefaultIfEmpty()
  
                                 where v.VehicleId == vehicleId
                                 select new { v, vehicleAttributes });
  </code></pre>
  
  <p>so far so good. VehicleAttribute has also a column AttributeId. And I only need to join those VehicleAttributes when it's in this List:</p>
  
  <pre><code>List&lt;Guid&gt; allowedAttributes = (from ua in context.UserAttributes
                                                      where ua.UserId == UserSession.CurrentUser.UserId
                                                      select ua.AttributeId).ToList();
  </code></pre>
  
  <p>How would I do that? I think a subquery might be the right approach but I'm struggling.. </p>
  
  <p>Thanks for all answers.</p>
  
  <p>EDIT: A different approach to explain my problem:
  I have these two queries </p>
  
  <pre><code>SELECT Vehicle.VehicleId,VehicleAttribute.AttributeId
  FROM Vehicle
  LEFT JOIN VehicleAttribute
  ON Vehicle.VehicleId = VehicleAttribute.VehicleId
  
  SELECT UserAttribute.AttributeId
  FROM UserAttribute
  WHERE UserAttribute.UserId = '4D0F8AD2-7A4D-4E29-A6D3-E5FCD6075388'
  </code></pre>
  
  <p>and want to combine them so I only get the attribute id's which are in the second query. 
  A where clause doesn't work because I still want the vehicleId even if there are no attributeIds </p>