locked
Convert C# LINQ to VB.Net RRS feed

  • Question

  • I was wondering if someone can help me convert the following code to VB.Net. Thanks a million!

    var data = from l in this.MyData.MyAccountLists

                       select new
                       {
                           LastName = l.LASTNAME,
                           FirstName = l.FIRSTNAME,
                           MiddleName = l.MIDDLENAME,
                           Suffix = l.SUFFIX,
                       };

    Saturday, October 8, 2011 6:23 AM

Answers

  •  

           It should look like this:

     

    Dim data = from l In Me.MyData.MyAccountLists _
                           Select New With _
                           {               _
                           .LastName = l.LASTNAME, _
                           .FirstName = l.FIRSTNAME, _
    		       .MiddleName = l.MIDDLENAME, _
                           .Suffix = l.SUFFIX, _
                           }
    

     


     


    Tom Overton

    • Edited by Tom_Overton Saturday, October 8, 2011 4:06 PM added dots
    • Proposed as answer by Alan_chen Monday, October 10, 2011 8:38 AM
    • Marked as answer by Alan_chen Saturday, October 15, 2011 7:58 AM
    Saturday, October 8, 2011 10:06 AM
  • Hi AZDev;

    Tom Overton's solution is just missing one thing. In the Select clause when using the With keyword the property names need to have a . before the name as follows:

     

    Dim data = from l In Me.MyData.MyAccountLists _
               Select New With _
               {               _
                   .LastName = l.LASTNAME, _
                   .FirstName = l.FIRSTNAME, _
                   .MiddleName = l.MIDDLENAME, _
                   .Suffix = l.SUFFIX _
               }
    

     

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Edited by Fernando Soto - MCSD Saturday, October 8, 2011 1:59 PM
    • Proposed as answer by Alan_chen Monday, October 10, 2011 8:38 AM
    • Marked as answer by Alan_chen Saturday, October 15, 2011 7:58 AM
    Saturday, October 8, 2011 1:59 PM
  •  

    Not a problem Tom. I am always doing the same thing jumping between C# and VB .Net, my biggest problem is putting a semicolon at the end of a VB line of code.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by AZDev-IOrtiz Thursday, November 3, 2011 2:27 PM
    Saturday, October 8, 2011 4:22 PM

All replies

  •  

           It should look like this:

     

    Dim data = from l In Me.MyData.MyAccountLists _
                           Select New With _
                           {               _
                           .LastName = l.LASTNAME, _
                           .FirstName = l.FIRSTNAME, _
    		       .MiddleName = l.MIDDLENAME, _
                           .Suffix = l.SUFFIX, _
                           }
    

     


     


    Tom Overton

    • Edited by Tom_Overton Saturday, October 8, 2011 4:06 PM added dots
    • Proposed as answer by Alan_chen Monday, October 10, 2011 8:38 AM
    • Marked as answer by Alan_chen Saturday, October 15, 2011 7:58 AM
    Saturday, October 8, 2011 10:06 AM
  • Hi AZDev;

    Tom Overton's solution is just missing one thing. In the Select clause when using the With keyword the property names need to have a . before the name as follows:

     

    Dim data = from l In Me.MyData.MyAccountLists _
               Select New With _
               {               _
                   .LastName = l.LASTNAME, _
                   .FirstName = l.FIRSTNAME, _
                   .MiddleName = l.MIDDLENAME, _
                   .Suffix = l.SUFFIX _
               }
    

     

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Edited by Fernando Soto - MCSD Saturday, October 8, 2011 1:59 PM
    • Proposed as answer by Alan_chen Monday, October 10, 2011 8:38 AM
    • Marked as answer by Alan_chen Saturday, October 15, 2011 7:58 AM
    Saturday, October 8, 2011 1:59 PM
  • Thanks , good catch Fernando!  I edited mine to show the dots , your example is the correct answer.   

    Tom Overton
    Saturday, October 8, 2011 4:08 PM
  •  

    Not a problem Tom. I am always doing the same thing jumping between C# and VB .Net, my biggest problem is putting a semicolon at the end of a VB line of code.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by AZDev-IOrtiz Thursday, November 3, 2011 2:27 PM
    Saturday, October 8, 2011 4:22 PM
  • Fantastic! Thanks Fernandoo and Tom for your help! I really appreciate it! Awesome job!
    Wednesday, October 12, 2011 3:13 PM
  • Hi AZDev;

    If the solutions of Tom and myself answered your question please mark them as as answer the question by clicking on "Mark As Answer" to complete the question.

    Thank you.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, October 12, 2011 6:37 PM