none
Query mutitiple Columns by lambda expression RRS feed

  • Question

  • My need is to Retrive multiple column by lamda expression

    I have basic idea about lambda expression.

    I have table called Customer. It has fields such as Customer_Id, Password,Customer_Name,Age.

    This is my code

     DataClasses1DataContext dc = new DataClasses1DataContext();
               var a= dc.Customers.Where(n=>n.Age>5).Select(n=>n);

               This is to select all the records. but i want only Customer name and age means what should i do

               will selectmany function work for this. If so how.

               Its quickly needed. please help

              Thanks in advance
    Saturday, February 26, 2011 1:59 PM

Answers

  • Hi Logee;
    This line of code will give you what you are looking for.
    var a= dc.Customers.Where( n => n.Age > 5).Select( n => new {n.Customer_Name, n.Age});
    
    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Logee Sunday, February 27, 2011 4:41 AM
    Saturday, February 26, 2011 2:52 PM

All replies

  • My need is to Retrive multiple column by lamda expression

    I have basic idea about lambda expression.

    I have table called Customer. It has fields such as Customer_Id, Password,Customer_Name,Age.

    This is my code

     DataClasses1DataContext dc = new DataClasses1DataContext();
               var a= dc.Customers.Where(n=>n.Age>5).SelectMany(n=>n);

               This is to select all the records. but i want only Customer name and age means what should i do

               will selectmany function work for this. If so how.

               Its quickly needed. please help

              Thanks in advance
    Saturday, February 26, 2011 9:01 AM
  • Hi Logee;
    This line of code will give you what you are looking for.
    var a= dc.Customers.Where( n => n.Age > 5).Select( n => new {n.Customer_Name, n.Age});
    
    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Logee Sunday, February 27, 2011 4:41 AM
    Saturday, February 26, 2011 2:52 PM
  • Hello Logee,

     

    Welcome to the MSDN Forum and thanks for posting here.

    I found that your issue has been solved in another question type thread posted by you. So I will merge this one to the answered one.

    Thanks for your understanding and support!

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 28, 2011 2:14 AM
    Moderator