我想请求有关for循环的帮助,该循环迭代DataTable
的行,我想将其更改为LINQ
查询以使其更快。有人可以帮忙吗?
for (i = 0; i < ds.Rows.Count; i++)
{
if ( m.EmailID.Equals ((ds.Rows[i["email"]).ToString()))
{
if (dsm.Exists(x => x.WorkOrderId == m.WorkOrderId))
{
}
else
{
DesktopSupportTicketModel dstm = new DesktopSupportTicketModel()
{
BranchId = Convert.ToInt32(ds.Rows[i["BranchID"]),
StoreName = ds.Rows[i["Storename"].ToString(),
Longitude = float.Parse(ds.Rows[i["Longitude"].ToString()),
Latitude = float.Parse(ds.Rows[i]["Latitude"].ToString()),
Address = ds.Rows[i["Address"].ToString(),};
dsm.Add(dstm)
}
}
}
}
答案 0 :(得分:1)
尝试类似这样的事情
var dstm = ds.Tables[0].AsEnumerable().Select(dataRow =>
new newDesktopSupportTicketModel {
BranchId = dataRow.Field<string>("BranchId"),
StoreName = dataRow.Field<string>("StoreName"),
email = dataRow.Field<string>("email"),
WorkOrderId = dataRow.Field<string>("WorkOrderId")
}
).ToList().Where(x =>
x.email == m.EmailID && x.WorkOrderId != m.WorkOrderId
).ToList();