DbLogic.cs 836 B

12345678910111213141516171819202122232425262728293031
  1. using System.Data;
  2. using Database.Database;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Database;
  5. public class DbLogic
  6. {
  7. public static async Task<int?> GenIdAsync(ModelContext dbContext, string sequence)
  8. {
  9. var conn = dbContext.Database.GetDbConnection();
  10. if (conn.State == ConnectionState.Closed)
  11. {
  12. await conn.OpenAsync();
  13. }
  14. var command = conn.CreateCommand();
  15. string query = "select " + sequence + ".nextval from dual";
  16. command.CommandText = query;
  17. var reader = await command.ExecuteReaderAsync();
  18. while (await reader.ReadAsync())
  19. {
  20. var title = reader.GetString(0);
  21. //await conn.CloseAsync();
  22. return int.Parse(title);
  23. }
  24. //await conn.CloseAsync();
  25. return 0;
  26. }
  27. }