views:

37

answers:

1

I have the following query:

SELECT S.[FlowOrder], S.[DESCRIPTION], COUNT(I.ID)
FROM WorkFlowStatus AS S
INNER JOIN Item AS I
    ON S.ID = I.StatusID
WHERE I.Installation = '1'
GROUP BY S.[Description], S.[FlowOrder]
ORDER BY S.[FlowOrder]

Which gives me the count of an item, grouped by a foreign key to workflow, outputting the descriptive name from my FK table.

I've go this far with the LINQ query (using LINQ-to-SQL) in the background:

var items = from s in _entities.WorkflowStatus
    join i in _entities.Items on s.ID equals i.StatusId
    into Statuses
    orderby s.FlowOrder
    select new {s.Description, ItemCount = Statuses.Count() };

How do I get the where clause in the SQL into this LINQ query?

+2  A: 

How about this?

var items = from s in _entities.WorkflowStatus
    join i in _entities.Items.Where(item=>item. Installation == "1") on s.ID equals i.StatusId
    into Statuses
    orderby s.FlowOrder
    select new {s.Description, ItemCount = Statuses.Count() };
drs9222