Hi,
Perhaps I was a not clear in my original post. The rows in the above code excerpt marked with tags //TJI will solve the issue.
// TJI Add tenant id
sql += ", tenant_id";
// TJI Add tenant id
sql += string.Format(", {0}", AppInfo.GetAppInfo().Tenant.Id);