排除相交项

Posted on 2010-11-29 21:59  gmtyt  阅读(145)  评论(0)    收藏  举报

排除相交项

  描述:查询城市包含A的顾客并从中删除城市以A开头的顾客,并按照顾客名字排序

  查询句法:

  


var 排除相交项 = (from c in ctx.Customers where c.City.Contains("A") select c).Except
  (from c in ctx.Customers where c.ContactName.StartsWith("A") select c).OrderBy(c => c.ContactName);

  对应SQL:


  SELECT [t1].[CustomerID], [t1].[CompanyName], [t1].[ContactName], [t1].[ContactTitle], [t1].[Address], [t1].[City], [t1].[Region], [t1].[PostalCode], [t1].[Country], [t1].[Phone], [t1].[Fax]
  FROM (
  SELECT DISTINCT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]
  FROM [dbo].[Customers] AS [t0]
  ) AS [t1]
  WHERE (NOT (EXISTS(
  SELECT NULL AS [EMPTY]
  FROM [dbo].[Customers] AS [t2]
  WHERE ([t1].[CustomerID] = [t2].[CustomerID]) AND ([t2].[ContactName] LIKE @p0)
  ))) AND ([t1].[City] LIKE @p1)
  ORDER BY [t1].[ContactName]
  -- @p0: Input String (Size = 2; Prec = 0; Scale = 0) [A%]
  -- @p1: Input String (Size = 3; Prec = 0; Scale = 0) [%A%]

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3