Chris Hayes
Chris Hayes

Reputation: 4037

How do you do alias in Select method (LINQ)

I'm trying to alias the string list with a named column:

var providers = EMRRepository.GetProviders().Select(x => x as name);

where 'GetProviders()' returns a List<string>

Upvotes: 11

Views: 24067

Answers (2)

Anthony Pegram
Anthony Pegram

Reputation: 126892

You are looking to select into a new anonymous type.

var providers = EMRRepository.GetProviders().Select(x => new { Name = x });

Upvotes: 2

Brandon Moretz
Brandon Moretz

Reputation: 7631

It's called a "Projection", just select a new anonymous type.

var projection = data.Select( x => new { FieldName = x.Property } );

Upvotes: 28

Related Questions