kosmakoff kosmakoff - 7 months ago 46
C# Question

How to make use of environment parameter passed to EntityFramework Core CLI

Some of Entity Framework Core CLI commands accept

parameter. For example
dotnet ef migrations list --environment <env_name>

The assembly where I keep migrations is separate from data entities assembly, therefore I had to derive from

And here comes my question: is there a way to get the environment parameter passed to CLI from inside my
class? I need this to apply specific environment's connections strings.

Thanks in advance.

Answer Source

Stupid me, after the day of looking around, I noticed that Create method of IDbContextFactory interface has the parameter of type DbContextFactoryOptions, which in turn has EnvironmentName property, which appears to be the one passed to CLI commands.

Case closed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download