Solved

C# Linq statement conversion to VB.NET

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

12 Experts available now in Live!

Get 1:1 Help Now