Guest User

Untitled

a guest
Aug 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. Is it possible to format the results of a query using a Lambda Expression?
  2. var results = userRepository.Get(u => u.Username == "JDoe" && u.Password == "123456");
  3.  
  4. Expression<Func<User,string>> userDisplay = u => u.Firstname + " " + u.LastName + " - " + u.CompanyName
  5.  
  6. var formatedResults = results.Format(userDisplay);
  7.  
  8. public class SearchResult
  9. {
  10. object EntityId {get; set;}
  11. object Displaytext {get; set;}
  12.  
  13. }
  14.  
  15. Func<User,string>> userDisplay = u => u.Firstname + " " + u.LastName + " - " + u.CompanyName;
  16.  
  17. var formatedResults = results.Select(userDisplay);
  18.  
  19. var formattedResults = results.Select(x=> new SearchResult { EntityId = x.Id, DisplayText = userDisplay(x){);
  20. //anonymous type
  21. var formattedResults = results.Select(x=> new { EntityId = x.Id, DisplayText = x.ToString()});
Add Comment
Please, Sign In to add comment