This is a migrated thread and some comments may be shown as answers.

How to get values in some column?

1 Answer 46 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
john
Top achievements
Rank 1
john asked on 28 Nov 2012, 09:28 AM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Doroteya
Telerik team
answered on 29 Nov 2012, 10:57 AM
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
            }).ToList();

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,
Doroteya
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
General Discussions
Asked by
john
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or