I work on asp.net core .I face issue i can't use List dirctly without convert to datatable
so How to use this code based on list without convert to datatable
C#
var BranchesList = _OsuBranch.GetList(x => x.BRTYPE =="BR" && x.OSU_Is_Active == "Y");
DataTable dsBranchs = ConvertListToDataTable(BranchesList);
if (dsBranchs.Rows.Count > 0)
{
foreach (DataRow br in dsBranchs.Rows)
{
strBranch = _OsuBranch.GetFirst(x => x.brcode == Convert.ToString(br["brcode"])).brcode.ToString(); //Convert.ToString(br["brcode"]).Trim();
AppID = _OsuBranch.GetFirst(x => x.brcode == strBranch).AppID.ToString();
}
}
public virtual List GetList(Expression> where)
{
return dbSet.Where(where).ToList();
}
public partial class OsuBranch
{
[Key]
public string brcode { get; set; }
public string AppID { get; set; }
public string jbrcode { get; set; }
public string BRTYPE { get; set; }
public string JSubUnit { get; set; }
public string DeptNo { get; set; }
public string OSU_Is_Active { get; set; }
}so How to use dirct list BranchesList and loop within it and assign strBranch and AppId

Naimish MakwanaRank #324 · 7.7K reputationPosted Jul 18, 2023, 11:57 PM EDT
To use the
BranchesListdirectly without converting it to aDataTable, you can modify your code as follows:var BranchesList = _OsuBranch.GetList(x => x.BRTYPE == "BR" && x.OSU_Is_Active == "Y"); if (BranchesList.Count > 0) { foreach (var branch in BranchesList) { strBranch = _OsuBranch.GetFirst(x => x.brcode == branch.brcode).brcode.ToString(); AppID = _OsuBranch.GetFirst(x => x.brcode == strBranch).AppID.ToString(); // Rest of your code... } }Thanks
Amit MohantyRank #112 · 20K reputationPosted Jul 19, 2023, 1:36 AM EDT
var BranchesList = _OsuBranch.GetList(x => x.BRTYPE == "BR" && x.OSU_Is_Active == "Y"); if (BranchesList.Count > 0) { foreach (var branch in BranchesList) { strBranch = branch.brcode; // No need to use Convert.ToString AppID = branch.AppID; // Perform further actions with strBranch and AppID as needed } }