Return to Snippet

Revision: 34743
at October 27, 2010 23:53 by housecor


Initial Code
using (var context = new SampleEntities())
			{
				var contacts = from c in context.Contacts
							   where c.FirstName == "Robert"
							   let foo = new
							   {
								   ContactName = new { c.Title, c.LastName, c.FirstName },
								   c.Addresses
							   }
							   orderby foo.ContactName.LastName
							   select foo;
				
				foreach (var contact in contacts)
				{
					var name = contact.ContactName;
					Console.WriteLine("{0} {1} {2}: # Addresses {3}",
						name.Title.Trim(), name.FirstName.Trim(),
						name.LastName.Trim(), contact.Addresses.Count());
				}
			}

Initial URL


Initial Description
Notice that the property name declared (foo) is used later in the query for the ORDERBY operator and SELECT statement.

Initial Title
Anonymous types as properties in LINQ

Initial Tags


Initial Language
C#