I am new to linq.
My code is as below . I need to give the type for results variable. What it should be ?
I tried with assigning results= Enumerable.Emoty<DataRow>(); and casting results to DataRow . But casting failed.
Can anyone tell this?
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
});
}
You are creating an anonymous type in your
selectclauses – these have no specific name (hence anonymous).Create a class to hold the results and use that as the type in your results.