Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Login
2
Reply
how to select two columns from DBContext linq c#?
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Mani Kandan
7y
265
1
Reply
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...
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to use Server.MapPath to go two folder using for loop?
Below are codes in c# and vb.net