Solved

C# Linq statement conversion to VB.NET

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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 …

749 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