My code is as below
try
{
SqlConnection mapperConnection = SqlAccessHelper.SqlHelper.GetOpenConnection(SqlConnectionHelper.SqlConnectionString());
var parameters = new DynamicParameters();
parameters.Add("@P_MarketId", marketId, DbType.Int32);
parameters.Add("@P_Output", dbType: DbType.Int32, direction: ParameterDirection.Output);
using (var multi = mapperConnection.QueryMultiple("USP_FetchMarketRecords", parameters, (SqlTransaction)null, 1000000, CommandType.StoredProcedure))
{
IEnumerable<MarketRecord.FItem> FItem = multi.Read<MarketRecord.FItem>();
IEnumerable<MarketRecord.FSubsystem> FSubsystem = multi.Read<MarketRecord.FSubsystem>();
objCResponseVO.addObject("FItem",FItem);
objCResponseVO.addObject("FSubsystem",FSubsystem);
}
}
catch (Exception ex) {
throw ex;
}
first read is fine . Second read of FSubsystem gives me the exception “Each grid can only be iterated once”. whats wrong here ?
When I traced it down in public IEnumerable Read() method during second read consumed property is true . How can i overcome from this.?
The underlying data-reader is a forwards only device; by calling
Reada second time, you move the reader forwards to the next grid. You should consume each grid in a forwards-only way. For example, you could re-order the statements:Or you could buffer: