user2300652
user2300652

Reputation:

Linq query with select needed to get specific properties from a list

I have a Linq query of which contains a List within a list. I thought I only wanted to have First record so I had the select part of my query written like this:

select new
{
     EtchVectors = vio.Shapes.FirstOrDefault().Formatted
}).ToList();

This works great, it returns first record and the list that I have aliased "vio" has a list in it ( public List Shapes { get; set; } and Parse contains 2 properties, Formatted and Original. As I am rewriting this it seems I do not have access to "Formatted" if I get rid of FirstOrDefault()

This returns BOTH Formatted and Original obviously

EtchVectors = vio.Shapes

but, I cannot obviously do this:

EtchVectors = vio.Shapes().Formatted  ( Shapes cannot be used like a method)

Should I be doing a different method or using a lambda ??

Upvotes: 2

Views: 598

Answers (1)

Travis J
Travis J

Reputation: 82287

I think you are looking for a projection

EtchVectors = vio.Shapes.Select( s => s.Formatted );

Upvotes: 3

Related Questions