I have the lambda expression like below
Projects.Where(Project => (Project.PostalCode == "5000"))
Its generating the sql query like
SELECT [Id] AS [Id], [Title] AS [Title], .........
[AddressLine1] AS [AddressLine1]
from Project where PostalCode == "5000"
Here I would like to generate select query in Lambda expression. Entity might be having more than 100 fields. I don’t want all of these fields, because it hits performance.
I need 5 to 8 columns that can be dynamically selected. The following works that I generated manually
Projects.Where(Project => (Project.PostalCode == "5000")).Select(p=>new{id=p.Id, titile=p.Title, desc=p.OwnDescription, pc=p.PostalCode})
I had gone through some of the posts and didnt get enough information. Anybody knows how to Build the Select Query dynamically?
I got the solution here. Nice interesting article with source code.
http://carlisknight.blogspot.in/2010/02/now-change-linq-statement-to-dynamic.html