Last post Sep 21, 2014 10:05 PM by Fei Han - MSFT
Sep 19, 2014 11:21 AM|KiloDunse|LINK
I have some problem building a good LINQ query, which can find systems –where the systems “contains” one or more parts. The parts have a referencepart, which the search is based on.
Find systems where SystemPartCollection contains the systemId and all partId – which is linked to the following referenceId’s.
Sep 19, 2014 11:46 AM|KiloDunse|LINK
This sql can find the systems... but i need linq code.
-- specified ReferencePartID
DECLARE @p0 Int = 1
DECLARE @p1 Int = 3
-- number of destinct ReferencePartID
DECLARE @p2 Int = 2
FROM [System] AS [t0]
SELECT max([t2].ReferencePartID) as maxID, [t2].ReferencePartID from [SystemPartCollection] AS [t1]
INNER JOIN [Part] AS [t2] ON [t1].[PartID] = [t2].[PartID]
([t0].[SystemID] = [t1].[SystemID] AND ([t2].[ReferencePartID] = @p0 OR [t2].[ReferencePartID] = @p1))
GROUP BY [t2].ReferencePartID
WHERE maxID >= @p2
Sep 21, 2014 10:05 PM|Fei Han - MSFT|LINK
Thanks for your post.
According to your description, if you’d like to convert existing SQL statements to LINQ, you could use
Linqer which is a SQL to LINQ conversion tool. It will help learning LINQ and convert exisiting SQL statements.
Hope it will be helpful to you.