linq to sql 关于any的用法,该怎么处理
3个回答
展开全部
Any
说明:用于判断集合中是否有元素满足某一条件;不延迟。(若条件为空,则集合只要不为空就返回True,否则为False)。有2种形式,分别为简单形式和带条件形式。
1.简单形式:
仅返回没有订单的客户:
var q =
from c in db.Customers
where !c.Orders.Any()
select c;
生成SQL语句为:
SELECT [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]
WHERE NOT (EXISTS(
SELECT NULL AS [EMPTY] FROM [dbo].[Orders] AS [t1]
WHERE [t1].[CustomerID] = [t0].[CustomerID]
))
2.带条件形式:
仅返回至少有一种产品断货的类别:
var q =
from c in db.Categories
where c.Products.Any(p => p.Discontinued)
select c;
生成SQL语句为:
SELECT [t0].[CategoryID], [t0].[CategoryName], [t0].[Description],
[t0].[Picture] FROM [dbo].[Categories] AS [t0]
WHERE EXISTS(
SELECT NULL AS [EMPTY] FROM [dbo].[Products] AS [t1]
WHERE ([t1].[Discontinued] = 1) AND
([t1].[CategoryID] = [t0].[CategoryID])
)
说明:用于判断集合中是否有元素满足某一条件;不延迟。(若条件为空,则集合只要不为空就返回True,否则为False)。有2种形式,分别为简单形式和带条件形式。
1.简单形式:
仅返回没有订单的客户:
var q =
from c in db.Customers
where !c.Orders.Any()
select c;
生成SQL语句为:
SELECT [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]
WHERE NOT (EXISTS(
SELECT NULL AS [EMPTY] FROM [dbo].[Orders] AS [t1]
WHERE [t1].[CustomerID] = [t0].[CustomerID]
))
2.带条件形式:
仅返回至少有一种产品断货的类别:
var q =
from c in db.Categories
where c.Products.Any(p => p.Discontinued)
select c;
生成SQL语句为:
SELECT [t0].[CategoryID], [t0].[CategoryName], [t0].[Description],
[t0].[Picture] FROM [dbo].[Categories] AS [t0]
WHERE EXISTS(
SELECT NULL AS [EMPTY] FROM [dbo].[Products] AS [t1]
WHERE ([t1].[Discontinued] = 1) AND
([t1].[CategoryID] = [t0].[CategoryID])
)
展开全部
linq to sql 关于any的用法
表结构
Rah_User :userid,username,isdelete
Rah_UserMemberShip :userid ,pwd
2个表的id是一对一
我想做一个 select a.*,b.* from Rah_user a,Rah_usermembership where a.userid=b.userid where a.username='aaa'
and a.isdelete=false and b.password ='pwd' 类似于这种功能的
但我
from a in context.Rah_User
join b in context.Rah_UserMemberShip on a.UserID equals b.UserID
where context.Rah_User.Any(aa=>aa.LoginName==username && aa.IsDeleted==false)
&& context.Rah_UserMemberShip.Any(bb=>bb.Passwd==pwd)
select a;
写不对。我想大家能不能帮我想想应该怎么写。
要求不要用where (m=>m.username=='aaa') 而是用any实现
表结构
Rah_User :userid,username,isdelete
Rah_UserMemberShip :userid ,pwd
2个表的id是一对一
我想做一个 select a.*,b.* from Rah_user a,Rah_usermembership where a.userid=b.userid where a.username='aaa'
and a.isdelete=false and b.password ='pwd' 类似于这种功能的
但我
from a in context.Rah_User
join b in context.Rah_UserMemberShip on a.UserID equals b.UserID
where context.Rah_User.Any(aa=>aa.LoginName==username && aa.IsDeleted==false)
&& context.Rah_UserMemberShip.Any(bb=>bb.Passwd==pwd)
select a;
写不对。我想大家能不能帮我想想应该怎么写。
要求不要用where (m=>m.username=='aaa') 而是用any实现
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
停课不停学 some 和any的特殊用法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询