好的我试着在Linq做一个if语句,并想知道是否有可能做类似的事情:
Dim loadFriends = From p In db.UserRelationships Where p.aspnet_User.UserName = User.Identity.Name _
Or p.aspnet_User1.UserName = User.Identity.Name And p.Type = 1 _
Select New With {if p.aspnet_user1.user = "a certan username" then .username = _
p.aspnet_user.username else .username = p.aspnet_user1.Username}
先谢谢。
谢谢tyrongower
这是查询是否有其他人有同样的问题:
Dim loadFriends = From p In db.UserRelationships Where p.aspnet_User.UserName = User.Identity.Name _
Or p.aspnet_User1.UserName = User.Identity.Name And p.Type = 1 _
Select New With {.username = If((p.aspnet_User1.UserName = User.Identity.Name), p.aspnet_User.UserName, p.aspnet_User1.UserName)}
答案 0 :(得分:1)
我不知道VB但是在c#中会是
username = (p.aspnet_user1.user == "a certan username")? aspnet_user.username:p.aspnet_user1.Username
我假设VB.NET有三元语法