Linq查询.net MVC的问题

时间:2011-04-04 17:33:53

标签: sql asp.net-mvc linq linq-to-entities

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());


    }

查询无法区分ShowA run 1和Show A run2中的性能它只是重复所有性能ShowA run1和Show A run2

1 个答案:

答案 0 :(得分:2)

我认为问题可能是你如何加入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
        };

没有on g.runId equals l.runId之类的东西,那么你将获得所有制作/运行的所有表演。