Hello Everyone,
How can I select only two columns from the table via linq from
DBContext ?I have tried,
Here run time error occurred.
- public List
ShowOfficesList() - {
- using (var context = new ReboxEntities())
- {
- var listPartnerOfficeName = from offices in context.PartnerOffices select new PartnerOffice() { idPartnerOffice = offices.idPartnerOffice, Officename = offices.Officename };
- return listPartnerOfficeName.ToList
(); - }
- }
Here compile time error occurred.
- public List
ShowOfficesList() - {
- using (var context = new ReboxEntities())
- {
- return context.PartnerOffices.Select(c => new { c.idPartnerOffice, c.Officename }).ToList();
- }
- }


Tapan PatelRank #614 · 3.9K reputationPosted Feb 19, 2017, 10:44 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Feb 17, 2017, 12:04 AM EST