?
Solved

C# Linq statement conversion to VB.NET

Posted on 2010-08-19
3
Medium Priority
?
302 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:jfeltjfelt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 33481040
Hi jfeltjfelt;

Not able to check this out right now but that should be correct.

Fernando
messagesByOtherUsername = (From m In messages _
                           Let otherUser = IIF(m.SenderUsername = username, m.RecipientUsername, m.SenderUsername) _
                           Group By oUser = otherUser Into mbu = Group _
                           Select New JsMessagesByUsername { _
                               .Username = oUser, _
                               .Messages = mbu.Select(Function(m) New JsMessage { _
                                                          .Id = m.MessageId, _
                                                          .Sender = m.SenderUsername, _
                                                          .Msg = m.MessageContents _
                                                      }).ToList() _
                           }).ToList()

Open in new window

0
 

Author Comment

by:jfeltjfelt
ID: 33481355
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

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 33481404
Excellent, glad I was able to help.  ;=)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question