如何按其他对象的属性对对象列表进行排序

时间:2021-07-12 20:15:48

标签: c# mysql wpf sorting listview

我有一个存储对象的数据库(Profile),其中两个对象属性是其他对象的 id(UserType、User),因此我必须执行一个 foreach 来获取和完成辅助对象(UserType、用户)在我获取所有主要对象(配置文件)之后,在我的列表视图中,我试图让对象按名称排序,但我不知道如何。

Image of the code that completes the secondary objects

List<Profile> lista = SqlProfile.GetAll(listOrder);
List<Profile> listatemp = new List<Profile>();
Profile profile;

foreach (Profile p in lista)
{
    profile = p;
    profile.UserEscolhido = SqlUser.Get(p.UserEscolhido.Id);
    profile.TipoUser = SqlUserType.Get(p.TipoUser.Id);
    listatemp.Add(profile);
}

listatemp.Sort();
ListView.ItemsSource = listatemp;

如果有任何帮助,我会使用 MySql

0 个答案:

没有答案