Chris_
Chris_

Reputation: 63

Problem with Linq query .net MVC

enter image description here

public ActionResult Performances(string id)
    {
        var query =
    from f in _db.Production
    join g in _db.Run on f.show equals g.Production.show
    join l in _db.Performance on g.startDate equals l.runStartDate
    where f.show == id
    select new ShowPerformance
    {
        Venuename = g.venue,
        Showname = f.show,
        RunStart = g.startDate,
        RunEnd = g.endDate,
        PerformanceDate = l.performanceDate,
        PerformanceTime = l.performanceTime
    };


    return View(query.ToList());


    }

The query can not distuingish between a performance in ShowA run1 and Show A run2 it just duplicates all performances ShowA run1 and Show A run2

Upvotes: 1

Views: 253

Answers (1)

Stuart
Stuart

Reputation: 66882

I think the problem might be how you join Performance to Run/Production

var query =
        from f in _db.Production
        join g in _db.Run on new {f.show, f.year} equals new {g.show, g.year}
        join l in _db.Performance on new {g.venue, g.startDate} equals new {l.venue, l.runStartDate}
        where f.show == id 
        select new ShowPerformance
        {
            Venuename = g.venue,
            Showname = f.show,
            RunStart = g.startDate,
            RunEnd = g.endDate,
            PerformanceDate = l.performanceDate,
            PerformanceTime = l.performanceTime
        };

without something like the on g.runId equals l.runId then you will get all the performances for all the productions/runs.

Upvotes: 2

Related Questions