Giter Site home page Giter Site logo

Comments (12)

ErikEJ avatar ErikEJ commented on May 22, 2024

Good suggestion, but you can just use the constructor that takes an optionsbuilder

from efcorepowertools.

MgSam avatar MgSam commented on May 22, 2024

The constructor is public DbContext(DbContextOptions options), so it is doesn't give access to the builder.

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

I meant DbContextOptions that you can build externally..

from efcorepowertools.

r3faat1 avatar r3faat1 commented on May 22, 2024

@ErikEJ Can you give an example of what you mean? I ran into the same problem. I would have a partial class that generates OnConfiguring, however, every time I run EF Power Tool, the generated file gets OnConfiguring added again.

So, you're saying, I could just do public DbContext(DbContextOptions options) on my non-generated partial file and configure my options there? If done so, optionsBuilder.IsConfigured will be set to true on OnConfiguring?

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

Just add:

public DataContext(DbContextOptions<DataContext> options)
            : base(options)
        {
        }

(This is automatically included in the latest daily build)

from efcorepowertools.

MgSam avatar MgSam commented on May 22, 2024

@ErikEJ I'm still not following how that is equivalent to allowing us to override OnConfiguring ourselves. Are you suggesting doing this?

//In partial class...

//User-defined constructor
public MyContext() : this(getOptions()) { }

private static DbContextOptions getOptions()
{
    var builder = new DbContextOptionsBuilder();
    //Do something here with builder
    return builder.Options;
}

That seems like a lot of plumbing for people to write just to get to an DbContextOptionsBuilder.

The OnConfiguring method generated by the handlebars template is literally useless- I don't understand why it exists or why you can't just remove it.

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

Whoa? Why do you mention Handlebars now?

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

Please provide a sample project, and indicate if you were using Handlebars or not.

from efcorepowertools.

MgSam avatar MgSam commented on May 22, 2024

@ErikEJ I think you are missing the point- why does OnConfiguring exist in the generated code?

It does literally nothing, except make this tool less useful because the user cannot provide their own implementation.

Handlebars has nothing to do with it- the output is the same is the same with or without it. I have included handlebar templates in my project only so that I can remove the generated OnConfigured method. I've made no other changes to the templates.

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

I assume you have selected the option to remove the connection string?

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

The generated DbContext (not using HandleBars) has this constructor:

   public DataContext(DbContextOptions<DataContext> options)
        : base(options)
    {
    }

Which allows you to construct a context like this from outside the generated code:

    public DataContext Create(string connectionString = null)
    {
        var optionsBuilder = new DbContextOptionsBuilder<DataContext>();
        optionsBuilder.UseInMemoryDatabase(_guid);
        var context = new DataContext(optionsBuilder.Options);
        return context;
    }

from efcorepowertools.

ErikEJ avatar ErikEJ commented on May 22, 2024

Closing but a well tested PR for this will be accepted

from efcorepowertools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.