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实现
------解决方案--------------------
where context.any(b=>.....)
------解决方案--------------------不走寻常路?说说你一定得使用ANY的理由?Any是用为判断是否存在符合某种条件的纪录
而你上面分明有Select,你到底是想判断还是想查询纪录?
C# code
bool isExist =
(from a in context.Rah_User join b in context.Rah_UserMemberShip on a.UserID equals b.UserID).Any(u => u.a.LoginName==username && !u.a.IsDeleted && u.b.Passwd==pwd)
------解决方案--------------------
bool isExist =
(from a in context.Rah_User join b in context.Rah_UserMemberShip on a.UserID equals b.UserID select new{a, b}).Any(u => u.a.LoginName==username && !u.a.IsDeleted && u.b.Passwd==pwd);