Linq を使用して次のような構造を注文する際に問題があります。
public class Person
{
public int ID { get; set; }
public List<PersonAttribute> Attributes { get; set; }
}
public class PersonAttribute
{
public int ID { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
人は次のようになります。
PersonAttribute Age = new PersonAttribute { ID = 8, Name = "Age", Value = "32" };
PersonAttribute FirstName = new PersonAttribute { ID = 9, Name = "FirstName", Value = "Rebecca" };
PersonAttribute LastName = new PersonAttribute { ID = 10, Name = "LastName", Value = "Johnson" };
PersonAttribute Gender = new PersonAttribute { ID = 11, Name = "Gender", Value = "Female" };
LINQ プロジェクションを使用して、選択した人物属性で昇順で人物のリストを並べ替えたいと思います。たとえば、Age で並べ替えたり、FirstName で並べ替えたりします。
私は次のようなことを試みています
string mySortAttribute = "Age"
PersonList.OrderBy(p => p.PersonAttribute.Find(s => s.Name == mySortAttribute).Value);
しかし、構文は私に失敗しています。手がかりはありますか?