0

I would like to ask for help with this for loop which iterates the rows of a DataTable, that I would like to change into a LINQ query to make it faster. Can anyone assist?

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) } } } } 
1
  • 2
    Kindly format the code Commented Mar 10, 2017 at 5:26

1 Answer 1

1

Try Something like this

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(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.