0
我需要最终使我的MVC表中的列有一串OrderNumbers。我似乎无法找出已经拥有的如何汇总Linq查询中的字符串列表?
public IEnumerable<OrderShippedListModel> GetRecentShippedOrders(string authenticatedUsername)
{
User currentUser = new User().GetUser(authenticatedUsername);
Order (from r in dc.Orders
where r.Location.OrganizationID == currentUser.OrganizationID
&& r.CloseDate != null
&& r.ProductShipDate != null
orderby r.LastModifiedDate descending
select new OrderShippedListModel
{
ID = r.ID,
OrderNumbers = r.Processes.Select(p=>p.OrderNumber), //This needs to aggregate to a string
Label = r.Label,
Location = r.Location.Label,
CreateDate = r.CreateDate,
ProductShipDate = r.ProductShipDate,
LastModifiedDate = r.LastModifiedDate,
CloseDate = r.CloseDate
}).Take(3);
}
集合这里是我的类模型
public class OrderShippedListModel
{
public int ID { get; set; }
public string Label { get; set; }
public string Location { get; set; }
[Display(Name = "Create Date")]
public DateTime CreateDate { get; set; }
[Display(Name = "Last Modified Date")]
public DateTime LastModifiedDate { get; set; }
[Display(Name = "Product Ship Date")]
public DateTime? ProductShipDate { get; set; }
[Display(Name = "Close Date")]
public DateTime? CloseDate { get; set; }
[Display(Name = "Job Numbers")]
public string OrderNumbers { get; set; }
}
这效率显着降低因为它会导致创建大量的中间字符串,因此会花费大量的时间分配新的字符缓冲区,并在缓冲区之间一遍又一遍地复制相同的数据。 – Servy
我不知道这是效率低下,谢谢你指出这一点。 – Paul