public void DeleteDocumentsNotExitsInList(List <DocumentInfo> listDocument, string tableName, int preferId) { DocumentSeachCriteria _cri = new DocumentSeachCriteria(); _cri.TableName = tableName; _cri.PreferId = preferId.ToString(); List <DocumentInfo> currentDocument = GetDocument(_cri); List <DocumentInfo> listDelete = new List <DocumentInfo>(); if (listDocument == null) { listDelete = currentDocument; } else { listDelete = currentDocument.Where(el2 => !listDocument.Any(el1 => el1.AutoID == el2.AutoID)).ToList(); } //delete data in tables if (listDelete.Count > 0) { string deleteIds = ""; List <string> filesName = new List <string>(); foreach (DocumentInfo document in listDelete) { deleteIds += document.AutoID + ","; } deleteIds = deleteIds.Remove(deleteIds.Length - 1); SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { DocumentDataLayer.GetInstance().DeleteDocuments(connection, deleteIds); } //delete file physical FilesHelpers.DeleteFiles(tableName, preferId.ToString(), filesName); } }