Closed WalterB-MAMC closed 6 months ago
Popular? I think you can run the Tool once specifying the individual physical paths.
At any rate in order to help I need a runnable repro as requested when you created this issue.
Not sure what I would put in a runnable repo as this is just a case of specifying where to put the files that the tool creates.
myApp.Domain
|--Entities
| |-Movies.cs
| |-Rentals.cs
|
myApp.Infrastructure
|--Data
| |-dbContext.cs
| |-Configurations
| |-MoviesConfiguration.cs
| |-RentalsConfiguration.cs
Now when I run the tool how can you get it to put the dbContext and the Configuration files in the myApp.Infrastructure
project in the solution and then put the entities in the myApp.Domain
project. If I add myApp.Domain.Entities
when I run the tool from the Infrastructure project it will put the file in the myApp.Infrastructure.myApp.Domain.Entities
folder that it will create. It does not understand that there are multiple projects in the solution.
Hope that helps, if not let me know.
Thanks.
Are you running the tool once or twice?
Also suggest you read the wiki docs for this advanced topic on file placement
The only way I can figure it out is to run it twice, once in the domain project, so that I can get the entities in the domain project and the run it again in the infrastructure project to get the dbcontext and the configuration files in the infrastructure project. If there is a way to run it once and have it put some files in one project and then put the other files in another project, I would love to know what the secret is. I looked at the wiki, but it is very limited on what all the options are for like the sub-namespaces and stuff. I did not find a way to do it. If I missed it, then I would love to know the secret.
You need to run it only once Did you not see the extensive examples in the wiki?
I have been up and down the wiki and have not seen anything for splitting file outputs to two different projects in one solution. I must not know what I am looking for to find what I am trying to do if you say it is there. Do you have a link to where in the wiki this is at?
That only works in the project that the tool is ran in. Because in the efpt.config.json
file there is only one place for the project root namespace, "ProjectRootNamespace": "myApp.Infrastructure"
. If the files are seperated into two different projects in the solution this stops me from saying put the entities in project A and the dbContext and Configurations in project B. This also does not allow for the @Using myApp.Domain.Entities
to be added to the dbContext or Configuration files as again the project root namespace is used, and sub-namespaces are appended to this.
For this to work we would need to add the ability to select the project to add the entities and dbContext and Configuration files to. Either by a dropdown box with the Project names or a textbox to type it in freely. Then the tools would need to make sure it adds the right @Using
paths to the files as needed. Then we can use this tool to separate items as we see fit within the solution with multiple projects.
Hopefully this makes sense now and thanks for your help with the link.
You can set namespace both for entity classes and DbContext classes.
I need a full repro in order to help you further.
Ok, I figured out how to get the namespaces to work so that I can point to the right locations in my solution. The only issue is that you cannot just run this one time in the solution, it has to be ran twice, once in each project because I am splitting the models/entities in one project and then the dbContext and configurations in another project. I cannot figure out how it would run once and split this since it seems the tool is project oriented and not solution oriented.
Unless you know of a way to do this, I think it is a limitation of the tool. All you have to do is create a solution with two projects and then try to have the tool separate the items out like I have said and write to both projects. For now, I will just move on as I figured out something that was going to make me touch all the configuration files every time, I regenerated the files by running the reverse engineer process.
Cool.
If you like my free tools, I would be very grateful for a rating or review on Visual Studio Marketplace or even a one-time or monthly sponsorship
Hello @WalterB-MAMC,
I ran into a similar situation like you and based on @ErikEJ wiki, indeed you can achieve something like the above, by just running the EF Core Power Tool only once from one project.
Below you can find the efpt.config.json
file I used for that:
{
"CodeGenerationMode": 4,
"ContextClassName": "AimmsDbContext",
"ContextNamespace": "Persistence.Data",
"FilterSchemas": false,
"IncludeConnectionString": false,
"ModelNamespace": "Common.Entities",
"OutputContextPath": "Data",
"OutputPath": "..\\SideBySidePoc.Common\\Entities",
"PreserveCasingWithRegex": true,
"ProjectRootNamespace": "SideBySidePoc",
....
}
And below you can see the output I got (I run the tool from the SideBySidePoc.Persistence
project):
Best regards to both of you and thank you @ErikEJ for the really nice tool you built!
Using the Clean Architecture I need to split the output of this tool into multiple projects and reference them from each project. So, let's say that I am going to put the entities in
myApp.Domain
project and the DBContext and Configurations in themyApp.Infrastructure
project. Here I will need to have the DBContext and the Configuraiton files refernece@Using myApp.Infrastructure.Entities
when using a sub namespace for the entities. Right now I can run the tool on both projects but then, I have to go into each file and manually change all the references.This being a popular architecture, among others that split this up, is there a way that the tool can allow for different projects and add the references as needed?