开发者

Linq Query If statement

Ok im trying to do a if statement in Linq and was wondering if it was possible to do something like:

            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}

Thanks in Advance.

Thanks tyrongower

here is the query if anyone else has this same problem:

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)}


I don't know VB but in c# is would be

 username = (p.aspnet_user1.user == "a certan username")? aspnet_user.username:p.aspnet_user1.Username

I assume there would be ternary syntax for VB.NET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜