I'm doing Left join to get not existing records on a table which has 50k records and the right hand side table has 200k records.
removed .Dispose()
calling from fianlly block
This is my case:
public int InsertRecord(DynamicParameters parameters, string sql, int? commandTimeout = null)
{
using (var transactionScope = new TransactionScope())
{
_db.Open();
using (var transaction = _db.BeginTransaction())
{
try
{
var Item = _db.Execute(sql, parameters, commandType: CommandType.StoredProcedure, commandTimeout: commandTimeout);
transaction.Commit();
transactionScope.Complete();
return Item;
}
catch (Exception ex)
{
transaction.Rollback();
throw ex;
}
finally
{
_db.Dispose();
}
}
}
return 0;
}
var parameters = new DynamicParameters();
parameters.Add("ImportInventoryID", inventoryMovementID);
parameters.Add("StoreID", storeID);
parameters.Add("Mode", 4);
DataMapper dataMapper = new DataMapper();
int result = dataMapper.ExecuteRecords(parameters, "dbo.ExecuteInventoryItemMaster", 500);
return true;
SELECT DISTINCT LTRIM(RTRIM(I.ItemNum)), LTRIM(RTRIM(I.AltSKU)), LTRIM(RTRIM(I.ItemName)), NumPerVenCase, I.Vendor_Number, I.DateCreated
FROM [dbo].Inventory I (NOLOCK)
LEFT JOIN [dbo].StoreItemMaster IIM (NOLOCK) ON LTRIM(RTRIM(I.ItemNum)) = IIM.StoreItemNumber
AND LTRIM(RTRIM(I.AltSKU)) = IIM.AltSKU
AND LTRIM(RTRIM(I.Vendor_Number)) = IIM.VendorNumber
AND IIM.StoreID = @StoreID
WHERE IIM.StoreItemNumber IS NULL
AND IIM.AltSKU IS NULL
AND I.ImportInventoryID = @ImportInventoryID
AND ISNULL(I.ItemNum, '') <> ''