public List <AcTransLineCktCondTypeForeign> ExtractAcTransLineCktCondTypeForeign(string oracleConnString) { using (OracleConnection con = new OracleConnection(oracleConnString)) { using (OracleCommand cmd = con.CreateCommand()) { try { con.Open(); cmd.BindByName = true; cmd.CommandText = @"select ID, PARENT_ENTITY_ATTRIBUTE_ID, CHILD_ENTITY_ATTRIBUTE_ID from ENTITY_ENTITY_RELN where :id=1 and ID IS NOT NULL and PARENT_ENTITY='AC_TRANSMISSION_LINE' and PARENT_ENTITY_ATTRIBUTE='ConductorType' and CHILD_ENTITY='CONDUCTOR_MASTER' and CHILD_ENTITY_ATTRIBUTE='Id'"; // Assign id parameter OracleParameter id = new OracleParameter("id", 1); cmd.Parameters.Add(id); //Execute the command and use DataReader to display the data OracleDataReader reader = cmd.ExecuteReader(); List <AcTransLineCktCondTypeForeign> acLineCondTypesForeign = new List <AcTransLineCktCondTypeForeign>(); while (reader.Read()) { AcTransLineCktCondTypeForeign acLineCondTypeForeign = new AcTransLineCktCondTypeForeign(); acLineCondTypeForeign.WebUatId = reader.GetInt32(0); acLineCondTypeForeign.AcTransLineCktWebUatId = reader.GetInt32(1); acLineCondTypeForeign.CondTypeWebUatId = reader.GetInt32(2); acLineCondTypesForeign.Add(acLineCondTypeForeign); } reader.Dispose(); return(acLineCondTypesForeign); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } } } }
public async Task <AcTransLineCkt> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, AcTransLineCktCondTypeForeign acLineCondTypeForeign, EntityWriteOption opt) { // get the conductor type of the entity ConductorType condType = await _context.ConductorTypes.SingleOrDefaultAsync(ct => ct.WebUatId == acLineCondTypeForeign.CondTypeWebUatId); // if conductor type doesnot exist, skip the import. Ideally, there should not be such case if (condType == null) { _log.LogCritical($"Unable to find ConductorType with webUatId {acLineCondTypeForeign.CondTypeWebUatId} while inserting AcTransLineCktCondType with webUatId {acLineCondTypeForeign.WebUatId}"); return(null); } // get the ac transmission line ckt of the entity AcTransLineCkt existingAcTransLineCkt = await _context.AcTransLineCkts.SingleOrDefaultAsync(acCkt => acCkt.WebUatId == acLineCondTypeForeign.AcTransLineCktWebUatId); // if ac transmission line ckt doesnot exist, skip the import. Ideally, there should not be such case if (existingAcTransLineCkt == null) { _log.LogCritical($"Unable to find AcTransLineCkt with webUatId {acLineCondTypeForeign.AcTransLineCktWebUatId} while inserting AcTransLineCktCondType with webUatId {acLineCondTypeForeign.WebUatId}"); return(null); } // check if we should not modify existing conductor type if (existingAcTransLineCkt.ConductorTypeId.HasValue && opt == EntityWriteOption.DontReplace) { return(existingAcTransLineCkt); } // if conductor type is not present, then insert or replace conductor type if (!existingAcTransLineCkt.ConductorTypeId.HasValue || opt == EntityWriteOption.Replace || opt == EntityWriteOption.Modify) { existingAcTransLineCkt.ConductorTypeId = condType.ConductorTypeId; await _context.SaveChangesAsync(); return(existingAcTransLineCkt); } return(null); }