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<PartnerOffice> 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<PartnerOffice>();
- }
- }
I have tried this also,
Here compile time error occurred.
- public List<PartnerOffice> ShowOfficesList()
- {
- using (var context = new ReboxEntities())
- {
- return context.PartnerOffices.Select(c => new { c.idPartnerOffice, c.Officename }).ToList();
- }
- }
Please help me...