I use these commano to do database first. dotnet ef dbcontext scaffold "server=localhost;port=3306;userid=root;password=;database=***;persistsecurityinfo=True" MySql.EntityFrameworkCore -o DataService/ModelsByMicroservice/Security --context-dir DataService/DBContexts -c SecurityContext -f
But I don't know if there is a flag to dont put my connection string in the context file. After the scaffolding there is these method in my context file
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseMySQL("server=localhost;port=3306;userid=root;password=*****;database=*****;persistsecurityinfo=True");
}
}
CodePudding user response:
Just use this option:
--no-onconfiguring