-1

我想将以下 where 子句添加到 Linq 查询。子查询如何使用 linq

WHERE (Restaurants.[IsActive] = 1) 
AND exists 
(
   select 1 from APIKeys 
   where ApiKey = 'on35e5xbt3m4cbcef4e4448t6wssg11o'
       and (KeyType = 1
       and  fk_RestaurantsID = [t2].[RestaurantsID]
       or KeyType = 2 
       and fk_RestaurantGroupID = RG.RestaurantGroupsID 
       and [t1].[fk_RestaurantsID] in 
           (SELECT RestaurantsID 
            FROM Restaurants 
            WHERE RestaurantGroupsID = RG.RestaurantGroupsID))
)
AND (0 = (COALESCE([t0].[fk_MembersID],0))) 
AND (1 = [t0].[fk_BookingStatusID]) 
AND ([t0].[Email] = 'nike.s@gmail.com') 
AND (([t0].[Phone] = '9999999990') OR ([t0].[MobilePhone] = '9999999990'))
4

1 回答 1

0

用于Any()生成翻译为 EXISTS 的子查询。例如 AdventureWorks 数据库示例:

from p in Products
where p.FinishedGoodsFlag &&
      SalesOrderDetails.Any(od => od.ProductID == p.ProductID)
select new { p.ProductID, p.Name }

将对数据库产生以下查询:

SELECT [t0].[ProductID], [t0].[Name]
FROM [Production].[Product] AS [t0]
WHERE ([t0].[FinishedGoodsFlag] = 1) AND (EXISTS(
    SELECT NULL AS [EMPTY]
    FROM [Sales].[SalesOrderDetail] AS [t1]
    WHERE [t1].[ProductID] = [t0].[ProductID]
    ))
于 2013-09-25T10:37:08.570 回答