Naming a projected anonymous type in LINQ

/ Published in: C#
Save to your folder(s)

Note that C# doesn't allow naming in the SELECT statement. Must use the LET operator for this purpose.

Copy this code and paste it in your HTML
  1. from c in context.Contacts
  2. where c.FirstName == "Robert"
  3. let ContactName = new {c.Title, c.LastName, c.FirstName}
  4. select ContactName

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.