EF Core Context

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
donk
Posts: 4
Joined: Thu 26 Jan 2017 14:48

EF Core Context

Post by donk » Mon 13 Feb 2017 18:52

Is there a way to not have the EF Core define the connection string OR have it try to get from a local app settings? I'm using dependency injection and this is being passed in via the option builder parameter.

Basically, I want this line to be commented out when the template generates!

Image
https://www.dropbox.com/s/rlhtx6wikaxhc ... g.png?dl=0

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Context

Post by Shalex » Wed 15 Feb 2017 14:02

Please open your *.efml model via Solution Explorer of your Visual Studio, double click the diagram surface to open Model Settings and select the "Use the following connection string from App.Config". Save the model to regenerate the code. Is that what you need?

Code: Select all

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(GetConnectionString("myModelConnectionString"));
        CustomizeConfiguration(ref optionsBuilder);
        base.OnConfiguring(optionsBuilder);
    }

    private static string GetConnectionString(string connectionStringName)
    {
        System.Configuration.ConnectionStringSettings connectionStringSettings = System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName];
        if (connectionStringSettings == null)
            throw new InvalidOperationException("Connection string \"" + connectionStringName +"\" could not be found in the configuration file.");
        return connectionStringSettings.ConnectionString;
    }

donk
Posts: 4
Joined: Thu 26 Jan 2017 14:48

Re: EF Core Context

Post by donk » Wed 15 Feb 2017 14:51

No, I don't have an app.settings for this project. I'm injecting the connection string info into this from MVC via the Startup.cs, so I don't want it to know anything about the connection string.

Code: Select all

 // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
	// Add framework services.

	services.AddDbContext<IQContext>(options =>
		options.UseSqlServer(Configuration.GetConnectionString("IqConnectionString")), ServiceLifetime.Scoped);

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Context

Post by Shalex » Thu 16 Feb 2017 12:27

Please modify a predefined EF Core template by removing the lines 1017 and 1022.

More information:

donk
Posts: 4
Joined: Thu 26 Jan 2017 14:48

Re: EF Core Context

Post by donk » Thu 16 Feb 2017 14:08

When I try to make a template into a user template it blows up EntityDeveloper. I have a support ticket in and I haven't gotten any response on it yet :(

donk
Posts: 4
Joined: Thu 26 Jan 2017 14:48

Re: EF Core Context

Post by donk » Thu 16 Feb 2017 14:18

Anytime I try to generate with a template other than the built-in EF Core, I get this error.

Even without changing the template once I make it into a user template it blows up.

Image

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Context

Post by Shalex » Fri 17 Feb 2017 16:09

We have asked for the additional information by email.

Post Reply