Linq 查询 .net MVC 的问题

发布于 2024-10-30 01:07:54 字数 706 浏览 0 评论 0原文

在此处输入图像描述

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 run1 和 Show A run2 中的表演,它只是复制 ShowA run1 中的所有表演并显示运行2

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2024-11-06 01:07:54

我认为问题可能在于如何将性能加入到运行/生产中,

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 这样的东西,那么您将获得所有生产/运行的所有性能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文