Linq to sql 如何在LINQtoSQL中检查以下场景?
用户:Linq to sql 如何在LINQtoSQL中检查以下场景?,linq-to-sql,Linq To Sql,用户: userid username password 1 venkat reddy sa 2 reddy as 3 re sa id userid lat lon 1 1 14.00 15.00 2 2
userid username password
1 venkat reddy sa
2 reddy as
3 re sa
id userid lat lon
1 1 14.00 15.00
2 2 15.00 17.23
3 3 15.00 17.23
id userid friendid isActive
1 1 2 true
1 2 1 true
位置:
userid username password
1 venkat reddy sa
2 reddy as
3 re sa
id userid lat lon
1 1 14.00 15.00
2 2 15.00 17.23
3 3 15.00 17.23
id userid friendid isActive
1 1 2 true
1 2 1 true
朋友:
userid username password
1 venkat reddy sa
2 reddy as
3 re sa
id userid lat lon
1 1 14.00 15.00
2 2 15.00 17.23
3 3 15.00 17.23
id userid friendid isActive
1 1 2 true
1 2 1 true
我需要进行查询,比如如果我传递了userid=1
和username=re
,那么我需要获取所有以re
开头的行,如果该用户已经是该userid
的朋友,则给出状态消息,比如已经是朋友
,以及他的用户名和userid。如果用户现在不是朋友,那么请提供他的详细信息,如用户名和用户ID
请告诉我
例如:userid=1 username=re
然后我需要像这样的输出
<OutputResponse>
<Response>
<userid>2</userid>
<username>reddy</username>
<lat>15.00</lat>
<lon>17.23</lon>
<status>already friend</status>
</Response>
<Response>
<userid>3</userid>
<username>re</username>
<lat>15.00</lat>
<lon>17.23</lon>
<status>not a friend as of now</status>
</Response>
</OutputResponse>
2.
红色的
15
17.23
已经是朋友了
3.
重新
15
17.23
现在还没有朋友
您可以从以下内容开始
int userid=1;
string username="re";
var result=(from q in Users
join qq in Location on q.id equals qq.userid
where q.Username.StartsWith(username)
select new
{
userid=q.Id,
username=q.Username,
lat=l.lat,
lon=l.lon,
status=Friends.Where(z=>z.Friendid==q.Id&&z.Userid==userid).Count()>0?"already friend":"not a friend as of now"
});