public async static void Generate() { try { var path = Directory.CreateDirectory(folderName); if (!path.Exists) { Directory.CreateDirectory(folderName); } var query = "SELECT Id, TipoRegistro, ClaveNomina, TipoDocumento, NoDocumento, MontoPagar, Cuenta FROM Nominas"; using (var _dbContext = new ApecDbContext()) { var nomina = await _dbContext.Nominas.FromSqlRaw(query).ToListAsync(); foreach (var item in nomina) { writeFileLine($"{item.TipoRegistro}|{item.ClaveNomina}|{item.TipoDocumento}|{item.NoDocumento}|{item.MontoPagar}|{item.Cuenta}"); } _dbContext.Dispose(); Console.WriteLine("Archivo generado"); } } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { using (var dbContext = new ApecDbContext()) { DataSeeder.SeedNomina(dbContext); dbContext.Dispose(); }; GenerarNomina.Generate(); Console.ReadLine(); }