我是linq的新手。應該是什麼類型的變量?
我的代碼如下。我需要給結果變量的類型。它應該是什麼?
我試着將results= Enumerable.Emoty<DataRow>();
和鑄造結果分配到DataRow
。但鑄造失敗。
任何人都可以這樣說嗎?
var results;
if (rbtnSystemTypes.IsChecked == true)
{
results = (from DataRow dr in objDataTable.Rows
let Markets = dr.Field<bool>("IsActiveMarkets") == true ? "Active" : "Inactive"
let Budgets = dr.Field<bool>("IsActiveBudgets") == true ? "Active" : "Inactive"
let Programs = dr.Field<bool>("IsActivePrograms") == true ? "Active" : "Inactive"
select new
{
SlNo = objDataTable.Rows.IndexOf(dr) + 1,
Country = dr.Field<string>("SystemType"),
Market = dr.Field<string>("Market"),
ProgramType = dr.Field<string>("JDFType"),
Markets = Markets,
Budgets = Budgets,
Programs = Programs
});
}
else
{
results = (from DataRow dr in objDataTable.Rows
let Markets = dr.Field<bool>("IsActiveMarkets") == true ? "Active" : "Inactive"
let Budgets = dr.Field<bool>("IsActiveBudgets") == true ? "Active" : "Inactive"
let Programs = dr.Field<bool>("IsActivePrograms") == true ? "Active" : "Inactive"
select new
{
SlNo = objDataTable.Rows.IndexOf(dr) + 1,
SubSystemType = dr.Field<string>("SubSystem"),
Market = dr.Field<string>("Market"),
SystemType = dr.Field<string>("SystemType"),
Markets = Markets,
Budgets = Budgets,
Programs = Programs
});
}
您是否期待從匿名對象到DataRow的魔法轉換?如果是這樣,你運氣不好。 – leppie 2012-04-02 11:21:02