.Net 6 UseMySql

使用nuget : Pomelo.EntityFrameworkCore.MySql;Microsoft.EntityFrameworkCore;

 1 public class DataContext : DbContext
 2     {
 3         public DbSet<QuartzTaskEntity> QuartzTas { get; set; }
 4 
 5         private IConfiguration configuration;
 6 
 7         public DataContext()
 8         {
 9             configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
10         }
11 
12         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
13         {
14             optionsBuilder.UseMySql(configuration.GetConnectionString("DefaultDB"), new MySqlServerVersion(new Version()), null);
15         }
16     }

 

posted @ 2022-06-10 13:58  EarlyTao  阅读(374)  评论(0编辑  收藏  举报