非常に基本的な質問。Linqの結果を変更するにはどうすればよいですか?
さらに詳しく説明するために、データベースの注文テーブルから注文リストを選択しました。結果をWebフォームのグリッドビューに表示する必要があります。まず、結果の一部を変更する必要があります。たとえば、「注文」フィールドに値がある場合は、「見積もり」フィールドを空白に変更する必要があります。結果をもっと精巧に操作しなければならない可能性があります。以前は、配列をループして変更することは可能でしたが、今日のプログラミングでは、ループが発生することを望んでいないようです。現時点では、リストを変更する必要があるために何か間違ったことをしているように、結果は読み取り専用のようです。
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();
}
}