【发布时间】:2021-06-07 13:42:21
【问题描述】:
我正在使用 System.Linq.Dynamic。
鉴于下面的这个父子(集合)模型,是否可以使用基于 createdDate 属性的 OrderBy Client 传递特定地址的 Id 进行排序?或者,客户端属性也可以用于主排序。它还必须按姓氏和名字排序。
public class Client
{
public int Id { get; set; }
public string FirstName{ get; set; }
public string LastName { get; set; }
public string Description {get; set;}
public string Type {get; set;}
public virtual ICollection<Address> Addresses { get; set; }
}
public class Address
{
public int Id { get; set; }
public DateTime createdDate { get; set; }
public DateTime modifiedDate { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string AddressLine3 { get; set; }
}
是否有通用的方法来处理所有场景?
-
OrderBy(Client.Addresses.Where("Id = @0", idValue).CreatedDate + " ASC , LastName DESC, FirstName DESC")
-
OrderBy("Type DESC, LastName DESC, FirstName DESC")
【问题讨论】:
-
试试
.OrderBy(Client.Addresses.First("Id = @0", idValue).CreatedDate).ThenBy(LastName).ThenBy(FirstName") -
@Emanuele First 只接受 1 个参数,我已经更新了我的问题
标签: c# dynamic-linq