Skip to content

Update Reverse Engineering wiki page #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jespersh opened this issue Oct 17, 2019 · 17 comments
Closed

Update Reverse Engineering wiki page #290

jespersh opened this issue Oct 17, 2019 · 17 comments

Comments

@jespersh
Copy link
Contributor

Looked at https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering as I just noticed the new dialog:
image

And I got a bit overwhelmed by all the options to be honest.

I think some screenshots of Solution Explorer with all the different options could help people (me) in the wiki.
My solution has a ***.Persistence project with DbContext and a ***.Domain project with entities. So I couldn't figure out this full control thing just by looking at it #197 (comment)

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 17, 2019

Agree, this is something I need to do!

If you could make a screenshot / text description of your folder layout, I can try to help (and get the first entry in the wiki update drafted at the same time!)

@jespersh
Copy link
Contributor Author

image

The references between the projects are like this:
image

For a bit of context: The application layer is "talking" with the persistence layer through interfaces in the application layer and DI registered in the persistence layer.

What I normally do is just reverse engineering new entities and copying the parts from AldenteDbContext2 (generated in Entities folder) to AldenteDbContext

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 17, 2019

assuming that you are running EF Core Power Tools in the Aldente.Journal.Domain, the following values should work:

Namespace: Aldente.Journal
Entity path: Entities
Entity Sub-namespace: Domain.Entities
DbContext path : c:\code\xxx\Aldenete.Journal.Persistence
DbContext sub-namepsace: Persistence

(and thanks for dog-fooding!)

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 20, 2019

@jespersh did you try this out?

@jespersh
Copy link
Contributor Author

Back in the work seat and tried this out. For the most part it worked as expected.
Then I had this oddity in my Aldente.Journal.Domain.csproj added:

<Project Sdk="Microsoft.NET.Sdk">
...
  <ItemGroup>
    <Compile Include="..\Aldente.Journal.Persistence\AldenteDbContext.cs" Link="AldenteDbContext.cs" />
  </ItemGroup>
...
</Project>

This is the only thing I'd even consider an error.
The few other oddities I met are either because of my namespace (entity and namespace named Journal) or unhandled mysql datatypes (zerofill).

Knowing what I know today, then I'd move the generated AldenteDbContext.cs into: c:\code\xxx\Aldenete.Journal.Persistence\Generated\, because I have some special bits too.

So the screenshots are these:
image

image

What I am wondering about is this:

  • My non-generated AldenteDbContext would have a dependency injected into its constructor. How do I avoid the constructors in the partial generated by the tool? Or am I using it incorrectly. Should this be done as a property injection instead?
...
    public AldenteDbContext(ISecrets secrets)
    {
        _secrets = secrets;
    }
...

Maybe a followup issue on this would be appropriate

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 21, 2019

1: What is your target framework in Aldente.Journal.Domain.csproj ?

2: The constructor issue - is that something that just happended now? Otherwise it sounds like a feature request, so feel free to post a new issue.

3: "unhandled mysql datatypes (zerofill)." - is that a MySQL provider issue/bug?

@jespersh
Copy link
Contributor Author

  1. netstandard2.0

  2. What I have been doing is using Reverse Engineer like this:

  • Reverse engineer the specific table(s) I haven't yet added to get the Entity model(s) and a 2nd DbContext (the DbContext that always ended up in the Domain project) for the specific entity/entities.
  • Copy the parts from the DbContext that ends up in the Domain project into the DbContext I actually use in the Persistence project.

That way I always ended up a DbContext I was in control of because I was always cut/pasting the newly reverse engineered parts.
If I needed to only use your partial as is, now that it is able to end up in the right location, then I think I'd need a constructor-less generated partial and without the OnConfiguring method. That way I can create my own partial and not worry about having to re-generate the Reverse Engineered DbContext.
My own partial would contain the OnConfiguring override and appropriate constructors. Do you think that's a reasonable feature request?

  1. Yeah. I should look into fixing that for them so I don't hit that issue, because those properties are just silently skipped in the Entity model yikes.

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 22, 2019

1: Looks like I should only be doing this for .NET Framework projects: https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/EFCorePowerTools/Handlers/ReverseEngineerHandler.cs#L247

2: That is not how you are supposed to use it !! 😄
So:
a: Why do you need a constructorless partial?
b: Why do you need OnConfiguring removed? You can just use the constructor with a DbContextOptions class.

            var optionsBuilder = new DbContextOptionsBuilder<AssetManagementContext>();
            optionsBuilder = optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            context = new AssetManagementContext(optionsBuilder.Options);

@jespersh
Copy link
Contributor Author

I'll try and throw together a small example with my usage on how I intend to use it if I had to rework my persistence layer

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 22, 2019

Don't spend too much time on it, I am not planning to make any changes to how the DbContext class is layed out, I just reuse the EF Core implementation.

@jespersh
Copy link
Contributor Author

It'll also mostly be for my own sake to see what I've learned about working with EFCore. That others will benefit for it is a bonus 😄

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 26, 2019

Then I had this oddity in my Aldente.Journal.Domain.csproj added:

Attempted to fix in latest daily build

@alexle1965
Copy link

Erik, this is to let you know I love your tool. I am trying out the .NET 5.0 features and I don't know how to tell the tool to move all of the Entity Configuration files to a specified directory and the same for the Result files for Stored Procedures. For the domain entities and dbContext, they are easy to do.

@ErikEJ
Copy link
Owner

ErikEJ commented Nov 13, 2020

@alexle1965 Please create new issues for feature suggestions or bug reports.

The Entity Configuration proposal is a duplicate of #423 .

For the Stored Procedure result files, where would you like them to be placed? - if this matters to you, please create a new feature suggestion with a proposal.

@alexle1965
Copy link

alexle1965 commented Feb 9, 2021 via email

@ErikEJ
Copy link
Owner

ErikEJ commented Feb 9, 2021

@alexle1965 It is documented here: https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#sql-server-stored-procedures - wonder why you were not able to find it?

@alexle1965
Copy link

alexle1965 commented Feb 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants