非常基本的問題。我該如何修改Linq結果?修改Linq結果
爲了進一步闡述,我從數據庫中的訂單表中選擇了訂單清單。我需要在網頁表單的gridview中顯示結果。首先,我需要修改一些結果。例如,當「訂單」字段有值時,「報價」字段應該更改爲空白。我可能需要對結果進行更精細的操作。在過去,可以循環訪問數組並修改它們,但是今天的編程似乎不希望發生循環。目前結果似乎是隻讀的,就好像我因爲需要修改列表而做錯了事情。
protected void fillGridView()
{
using (CqsDataDataContext cqsDC = new CqsDataDataContext())
{
var orderlist = from x in cqsDC.MasterQuoteRecs
where x.CustomerNumber == accountNumber && x.DateCreated > DateTime.Now.AddDays(howfar)
orderby x.DateCreated descending
select new
{
customer = x.customername,
order = x.OrderReserveNumber,
quote = x.Quote,
date = Convert.ToDateTime(x.DateCreated).ToShortDateString(),
project = x.ProjectName,
total = x.Cost,
status = x.QuoteStatus
};
// I would like to loop thru list and make changes to it here
GridView1.DataSource = orderlist;
GridView1.DataBind();
}
}
如果要進行更改,請更改查詢。順便說一句,這不是一個列表。 –
在查詢中,我需要做的更改(在路上)可能無法完成。什麼是對象而不是列表? – Dave
你是試圖在數據庫中進行更改,還是隻是爲了顯示?如果您試圖在數據庫中進行更改,請將其更改爲「select x」,進行所需的更改,最後執行'cqsDC.SubmitChanges();'。如果只是爲了顯示,使它成爲'quote = x.Order == null? x.Quote:null'。 –