I have the following SQL query:
SELECT C.ID, C.Name FROM Category C JOIN Layout L ON C.ID = L.CategoryID
JOIN Position P ON L.PositionID LIKE '%' + CAST(P.ID AS VARCHAR) + '%'
WHERE P.Code = 'TopMenu'
and following data
Position:
ID Code
1 TopMenu
2 BottomMenu
Category
ID Name
1 Home
2 Contact
3 About
Layout
ID CategoryID PositionID
1 1 1
2 2 1,2
3 3 1,2
With the above data, is it possible to convert the SQL query to LINQ or Lambda expression?
Any help is appreciated!
This might do what you want:
Although you might want to materialize the ‘Position’ sub query to save on time like so:
I do, however, agree with Jon that to really make your life simpler you should change the way you’re handling the many-to-many relationship by creating a ‘Layout_Position’ table.