我想用linq來分組一些數據,然後根據查詢中的值更新一個propety。根據linq查詢的結果更新屬性
例如
var list = from c in Transactions()
group c by c.StoreID into g
select new TransactionDetail{
Description = g.FirstOrDefault().Descrip,
BusinessName = g.FirstOrDefault().BusinessName,
TransactionAmount = g.Where(cr => cr.EntryType == cnCommon.INSERT_ENTRY).Sum(cr=>cr.TransactionAmount).Value,
PurchasesRequired = g.FirstOrDefault().PurchasesNeeded
};
foreach (TransactionDetail item in list)
{
item.ProgressBar = (230/item.PurchasesRequired) *Convert.ToInt32(item.TransactionAmount);
}
lstTransactions.DataSource = list.ToList();
lstTransactions.DataBind();
}
public class TransactionDetail
{
public string Description { get; set; }
public string BusinessName { get; set; }
public double TransactionAmount { get; set; }
public double TransactionsCompleted { get; set; }
public int PurchasesRequired { get; set; }
public bool IsRedeemable { get; set; }
public int Balance { get; set; }
public int ProgressBar { get; set; }
}
查詢工作正常,但是當我做foreach循環TransactionDetail.ProgressBar沒有更新。
你能看到我在做什麼錯嗎?
當然.......我忘了tolist :( – 2010-11-18 18:47:52