0

I need to generate the dynamic cross join linq query for the below sql Query

SQL - Select Query for complex dynamic rows

I need to create number of subquery joins(Listing Table) based on ExtraField Count .

If ExtraField Count = 4 , create 4 cross joins.

If ExtraField Count = 2 , create 2 cross joins only.

SELECT  t1.ListingID
FROM    Listing AS t1 
        INNER JOIN Listing AS t2
            ON t2.ListingID = t1.ListingID 
        INNER JOIN Listing AS t3
            ON t3.ListingID = t1.ListingID 
        INNER JOIN Listing AS t4
            ON t4.ListingID = t1.ListingID 
WHERE   (t1.ExtraFieldID = 1 AND t1.Value = 1)
AND     (t2.ExtraFieldID = 2 AND t2.Value = 7)
AND     (t3.ExtraFieldID = 3 AND t3.Value = '')
AND     (t4.ExtraFieldID = 4 AND t4.Value = 1999)
Community
  • 1
  • 1
m rajesh
  • 15
  • 6
  • These do not appear to be Cross Joins. Are you sure you are using the correct term? – cadrell0 Feb 24 '12 at 17:59
  • All 4 joins are made on the same table. Please look at the link to get an idea. http://stackoverflow.com/questions/9376514/sql-select-query-for-complex-dynamic-rows – m rajesh Feb 24 '12 at 18:52
  • Why do you want to reproduce exact SQL with linq? It's like showing IL code and asking what C# will produce that. This really is not a rant, but I think the great thing of LINQ(to sql/entities) is that we can focus on _what_ we want to achieve rather than on _how_ to do it. So I'd encourage you to focus on the use case, not the ceremonial. – Gert Arnold Feb 26 '12 at 18:48

0 Answers0