0

Just wondering how the following sql query would look in linq for Entity Framework...

SELECT  KPI.*
FROM    KeyPerformanceIndicator KPI
    INNER JOIN (
        SELECT  SPP.SportProgramPlanId
        FROM    SportProgramPlan PSPP
            INNER JOIN SportProgramPlan ASPP
                ON (PSPP.SportProgramPlanId = @SportProgramPlanId
                    AND PSPP.StartDate >= ASPP.StartDate
                    AND PSPP.EndDate <= ASPP.EndDate)
    ) AS SPP
        ON KPI.SportProgramPlanId = SPP.SportProgramPlanId

Cheers Anthony

2
  • Some part of your query is missing -- there are two ( and one ). Perhaps the start of the WHERE clause? Commented Mar 9, 2010 at 5:31
  • Missing bracket fixed... Commented Mar 9, 2010 at 6:01

1 Answer 1

1

Hard to say without seeing the associations in your model. Would there be a self-referential association on SportProgramPlan?

The SQL seems like an error to me as PSPP and ASPP could be the same record, and I'm not sure you want that? At any rate, it's trivial to exclude....

Here's a shot at it:

var q = from kpi in Context.KeyPerformanceIndicators
        where kpi.SportProgramPlan.Id = sportProgramPlanId 
            && Context.SportProgramPlans.Any(aspp => 
                                                 spp.StartDate >= aspp.StartDate
                                                 && spp.EndDate <= aspp.EndDate))
        select ...
Sign up to request clarification or add additional context in comments.

3 Comments

I am trying to bring across the query you provided but the 'Any' method isn't a part of SportProgramPlans... any ideas?
KeyPerformanceIndicator has only 1 SportProgramPlan but 1 SportProgramPlan can have many KeyPerformanceIndicators...
OK; updated for that cardinality, but see the note; I'm not sure your original SQL is right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.