Solved

C# Linq statement conversion to VB.NET

Posted on 2010-08-19
3
295 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
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 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 62

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now