I have a Users
and a Shipments
table. The Shipments
table has a property Received
. I want to write code to get all Users
where all their shipments have been received (received == true
) with linq.
Users
table
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool NeedsFilament { get; set; }
public ICollection<Shipment> Shipments { get; set; }
Shipments
table
public Guid Id { get; set; }
public int Quantity { get; set; }
public DateTime DateShipped { get; set; }
public bool Recieved { get; set; }
public Guid UserId { get; set; }
public User User { get; set; }
What I've done so far in a SQL query that doesn't count the Received
props in Shipments
but just gets the distinct (it's wrong)
SELECT DISTINCT
[FirstName]
,[LastName]
,[Username]
,[Address]
,[LatestShippedDate]
,[PrinterActive]
,[ProductionDate]
,[ShippedQuantity]
,[Email]
,[PhoneNumber]
,[NeedsFilament]
,[FilamentTrackingNumber]
,[SentFilamentDate]
,[LatestShippedQuantity]
FROM
[dbo].[Users]
LEFT JOIN
Shipments ON Shipments.UserId = Users.Id
WHERE
Shipments.Recieved = 1
AND Users.NeedsFilament = 1