Link to home
Start Free TrialLog in
Avatar of jfeltjfelt
jfeltjfeltFlag for United States of America

asked on

C# Linq statement conversion to VB.NET

I have been converting some C# code to VB for use in a web project.  I'm not familiar with LINQ, but translating this code has been an extremely educational experience.  I apologize if the code snippet does not format correctly. I've been able to convert all of the code so far except for the following statement:

 
messagesByOtherUsername = (from m in messages
                                           let otherUser = m.SenderUsername == username ? m.RecipientUsername : m.SenderUsername
                                           group m by otherUser into mbu
                                           select new JsMessagesByUsername { Username = mbu.Key, Messages = mbu.Select(m => new JsMessage { Id = m.MessageId, Sender = m.SenderUsername, Msg = m.MessageContents }).ToList() }).ToList();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jfeltjfelt

ASKER

That was close enough to get me to the code below.  Thank you for your help.
messagesByOtherUsername = (From m In messages _
                                           Let otherUser = IIf(m.SenderUsername = username, m.RecipientUsername, m.SenderUsername) _
                                           Group m By oUser = otherUser Into mbu = Group _
                                           Select New JsMessagesByUsername With { _
                                                .Username = oUser, _
                                                .Messages = mbu.Select(Function(m) New JsMessage With { _
                                                                        .Id = m.MessageID, _
                                                                        .Sender = m.SenderUsername, _
                                                                        .Msg = m.MessageContents _
                                                                        }).ToList() _
                                            }).ToList()

Open in new window

Excellent, glad I was able to help.  ;=)