【问题标题】:converting SQL statement into linq expression [duplicate]将SQL语句转换为linq表达式[重复]
【发布时间】:2017-04-28 08:26:55
【问题描述】:

我需要帮助来将此 SQL 语句转换为 linq 表达式

        select user_ID, ticket_type, count (ticket_type) as Total

        FROM database

        group by user_ID, ticket_type

        order by user_ID, ticket_type

当我试图在 linq 表达式中编写 2 group by 时,我卡住了

var list2 = from p in list
            group p.Ticket.user_ID by p.Ticket.user_id;
            group p.Ticket.ticket_type by p.Ticket.ticket_type

谁能帮忙?

【问题讨论】:

  • 做这样的事情var list2 - list.GroupBy(x => new { x.user_ID, x.ticket_type })

标签: c# sql sql-server linq sql-to-linq-conversion


【解决方案1】:

var list2 = list.select(p).GroupBy(p => p.user_ID, p => p.ticket_type).OrderByDescending(g => user_ID).ToList()

【讨论】:

    猜你喜欢
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多