* 我刚刚发现了我的错误!对不起大家!请参阅问题的结尾以获取解决方案,或继续阅读以发现问题*
我正在尝试根据名为“重量”的对象的属性返回 List<>。
我正在尝试这个:
public List<ReferenceTypeDto> GetAllResourceTypes()
{
var unordered = rd.GetAllResourceTypes();
var ordered = unordered.OrderBy(t => t.Weight).ToList();
return ordered;
}
但顺序似乎没有改变。我究竟做错了什么?
我调用的方法是这样定义的:
public List<ReferenceTypeDto> GetAllResourceTypes()
{
var types = (from c in _context.resource_type
select new ReferenceTypeDto
{
Description = c.Description,
Id = c.Id
}).ToList();
return types;
}
ReferenceTypeDto 的定义如下:
public class ReferenceTypeDto
{
public int Id { get; set; }
public string Description { get; set; }
public int Weight { get; set; }
public override string ToString()
{
return Description;
}
}
* 发现错误!我忘记将“重量”值分配给我正在排序的对象的属性!!抱歉耽误您的时间... *