Solved

C# Linq statement conversion to VB.NET

Posted on 2010-08-19
3
297 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 63

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 63

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System.Security 2 27
Media.Imaging 1 18
Service Controller 1 23
C# winforms programmitically move panels 6 29
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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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