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