linq to entities - 尝试这个!

时间:2009-09-30 10:17:56

标签: sql linq

我转换为linq到实体,我发现尝试转换我创建的存储过程作为数据概述的问题。

如何将此sql语句转换为linq到实体:

我有一张带有儿童venuerooms桌子的场地桌。在最后一部分,我希望在所有房间和房间类型中获得该场地的最大容量。

目前在sql server 2005中工作

任何帮助都会受到高度赞赏

ALTER proc [dbo].[sp_getVenueOverview]
   (@venue varchar(100)) as
   SELECT (Select accomrooms
        from tblvenue
        where venueid=(select venueid from tblvenue where urlfriendly = @venue))
        as accomrooms,
        (Select count(*)
         from tblvenueroom
         where venueid=(select venueid from tblvenue where urlfriendly = @venue))
         as roomcount,
        (Select Max(dbo.Greatest(theatrestyle,classroom,boardroom,ushape,banquet,cocktail))
        from tblvenueroom
        where venueid=(select venueid from tblvenue where urlfriendly = @venue))
        as largest

1 个答案:

答案 0 :(得分:0)

您可能希望首先重构查询,这是我的尝试:

SELECT 
    v.accomrooms,r.roomcount,r.largest
    FROM tblvenue  v
        LEFT OUTER JOIN (SELECT
                             v.venueid
                                 ,COUNT(*) AS roomcount
                                 ,Max(dbo.Greatest(r.theatrestyle,r.classroom,r.boardroom,r.ushape,r.banquet,r.cocktail) AS largest --dbo.Greatest() kills performance!
                             FROM tblvenue                 v
                                 INNER JOIN tblvenueroom   r ON v.venueid=r.venueid
                             WHERE v.urlfriendly = @venue
                             GROUP BY v.venueid
                        ) dt ON v.venueid=dt.venueid
    WHERE v.urlfriendly = @venue