Open Relki opened 2 years ago
Also, when I use dotnet ef migrations add InitialCreate to create migrations, it creates a folder called "Migrations" in the root of the EF project. But when I click save on the efModel, just like the partial classes, it goes through and deletes the migration and snapshot files that dotnet ef creates.
It seems like the generating code walks through and just deletes any code files in any folders. I just tried today to move the model efmodel file and model.tt file into a sub folder instead of the root folder, and then tried same process again. Still deletes any partial classes I create and any migrations created.
Is there a recommended way to create migrations with this designer extensions? I haven't found anything in the Wiki talking to this.
Next I'm going to just tell dotnet ef to generate migration files in the root folder of EF. Maybe then the generated designer code will ignore them.
This designer seems to make using migrations not possible with default documentation from Microsoft. Going to try pointing to root folder today and will have to accept that as a work around for now if it works.
I've never seen this behavior before. Can you provide a small sample solution where you see the problem occur?
I've pulled the Entity Framework projects out of my solution, built a separate solution with my Entity Framework project set up that reproduces this issue.
Note, this project is using .Net 7.0 now. It was using .Net 6.0 and the issue reproduced with that framework as well.
When you open the solution, take note that I have put the partial classes in the same folder as the other Entities. Example;
Versona.EF\Models\TableEntities\Account.cs Versona.EF\Models\TableEntities\Account.ShouldSerialize.cs
Account.cs is auto generated, but Account.ShouldSerialize.cs is my partial class implementation. There are several other entities in the same folder with the same naming format.
Also, same pattern with the DbContext;
Versona.EF\Models\Contexts\VersonaModelContext.cs Versona.EF\Models\Contexts\VersonaModelContext.Implemented.cs
Now, to reproduce the issue;
The only way I could prevent this from happening, was to move all those partial classes, to the root project level. Then they don't get deleted whenever code is generated.
Now, as a note, I did try creating a new project and adding Visual Entity Framework to it again, created a simple Entity with 1 table, and then created a partial class for that same table in the same folder as the auto generated code. When I generated code, it did not delete the partial classes.
So, I could not reproduce this with a brand new project with just 1 table entity. But it does reproduce in my larger project with many entities. I have two such projects, with many entities (Account.EF and Versona.EF). Both larger projects have the exact same issue reproduced.
I had the same problem as well if I created a folder in Versona.EF project called "Migrations". I use to have all my migrations under that folder. However, when the code was generated, it also deleted all the migration class files as well. Imagine my surprise. I had to either move my migration files to the root folder or move them to a separate project (which I ended up doing).
Was the repro helpful?
Discussed in https://github.com/msawczyn/EFDesigner/discussions/317