I need to make multiple db calls by looping through the connection strings. There is only 1 matching record across dbs and If I find a matching record then I can return data and cancel other async calls.
using (var Contexts = instContextfactory.GetContextList())
{
foreach(var context in Contexts.GetContextList())
{
// how do I make all the calls and return data from the first call that finds data and continue with further process.(don't care about other calls if any single call finds data.
context.Insurance.GetInsuranceByANI(ani);
}
}
GetInsuranceByANI
public Task<IEnumerable<Insurance>> GetInsuranceByANI(string ani)
{
using (ITransaction transaction = Session.Value.BeginTransaction())
{
transaction.Rollback();
IDbCommand command = new SqlCommand();
command.Connection = Session.Value.Connection;
transaction.Enlist(command);
string storedProcName = "spGetInsurance";
command.CommandText = storedProcName;
command.Parameters.Add(new SqlParameter("@ANI", SqlDbType.Char, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Default, ani));
var rdr = command.ExecuteReader();
return Task.FromResult(MapInsurance(rdr));
}
}
For example : I'm looping through with 5(a, b, c, d, e) different db connection strings. I need make asyn calls to all the 5 dbs. If I find matching record in db : b then I can return that data and continue to next steps and can stop making calls to other dbs