How to get values in some column?

2 posts, 1 answers
  1. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 28 Nov 2012 Link to this post

    I have a Customer class with CustomId, CustomerName, Age, Sex, BirthDate. If I only want to retrieve CustomerId and Age column, how can I write code for filling Customer class with two columns?
  2. Answer
    Doroteya avatar
    497 posts

    Posted 29 Nov 2012 Link to this post

    Hello John,

    The best way to retrieve a subset of columns from a given class is by LINQ. The necessary statement should look like this:
    IList<Customer> result = (from customers in dbContext.Customers
               select new Customer
                    CustomerId = customer.CustomerID,
                    Age = customer.Age

    In addition, the How to: Read a Subset of Columns article gives a detailed, step-by-step answer to your question.

    If you experience any difficulties or have other questions, do not hesitate to get back to us.

    Kind regards,
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  3. DevCraft banner
Back to Top