For example, if I have the following data table layout:dt.Columns.Add(ticketid, typeof(Int32));dt.Columns.Add(createtime, typeof(DateTime));dt.Columns.Add(creator, typeof(string));dt.Columns.Add(ticketText, typeof(string));If I want to add a new entry I need to make sure that there exists none already that has the same primary key (ticketid, createtime, creator).The check is as follows:if (    dt.Rows.Count <= 0 ||    (        dt.Rows.Count > 0 &&                    null == dt.AsEnumerable().Where                        (                            r => r.Field<int>(ticketid) == newEntry.TicketId                                && DateTime.Equals(r.Field<DateTime>(createtime), newEntry.CreateTime)                                && r.creator == newEntry.Creator                         )                         .FirstOrDefault()   ))The code does what it is meant for, BUT my problem is that it is SLOW. In my case I need to read 2 million entries from the file and put them into the database as fast as possible at which this code fails (as soon as I use the code the runtime goes from just 1 minute to over 30 minutes). Is there any faster way to do this?Site-note: the datatable is read from a file and the above is a check to make sure the data is ok before it is bulk inserted into the db.Example with happenings:if (    dt.Rows.Count <= 0 ||    (        dt.Rows.Count > 0 &&                    null == dt.AsEnumerable().Where                        (                            r => r.Field<int>(ticketid) == newEntry.TicketId                                && DateTime.Equals(r.Field<DateTime>(createtime), newEntry.CreateTime)                                && r.creator == newEntry.Creator                         )                         .FirstOrDefault()   )){    // No duplicate found so insert the data into the data table   dt.Rows.Add(new object[] {newEntry.TicketId, newEntry.CreateTime, newEntry.Creator});}
Determining if a possible new entry already exists in a dataset
c#;performance;console