Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it possible to format the results of a query using a Lambda Expression?
- var results = userRepository.Get(u => u.Username == "JDoe" && u.Password == "123456");
- Expression<Func<User,string>> userDisplay = u => u.Firstname + " " + u.LastName + " - " + u.CompanyName
- var formatedResults = results.Format(userDisplay);
- public class SearchResult
- {
- object EntityId {get; set;}
- object Displaytext {get; set;}
- }
- Func<User,string>> userDisplay = u => u.Firstname + " " + u.LastName + " - " + u.CompanyName;
- var formatedResults = results.Select(userDisplay);
- var formattedResults = results.Select(x=> new SearchResult { EntityId = x.Id, DisplayText = userDisplay(x){);
- //anonymous type
- var formattedResults = results.Select(x=> new { EntityId = x.Id, DisplayText = x.ToString()});
Add Comment
Please, Sign In to add comment