Giter Club home page Giter Club logo

Comments (4)

gregveres avatar gregveres commented on June 15, 2024

I searched my project for .edmx files and there are none. Should there be when using code first migrations?
In the migration folder there are .cs and .resx files but no .edmx files.

from c3d.msbuild.tools.ef6.generateviews.

CZEMacLeod avatar CZEMacLeod commented on June 15, 2024

Okay. I suggest you add another project to your solution that is just the console app - similar to the sample, but adjusted to look at your Models project and DbContext. I am slightly surprised your migrations are not in the same project as the DbContext, but that is your choice.
When you run the console app, it should generate an edmx file next to the assembly dll (with the same name as the assembly but with an .edmx extension). This will probably be in the bin/Debug folder.
Copy that file to your models project, which should also have the nuget package, and set the build type to EntityView, and set the Custom Tool Namespace to the same as your DbContext.

In the future, when you run Add-Migration, you will need to re-run the console app and copy the new EDMX file to your Models project.

I don't actually use Add-Migration / Update-Database myself - I have some code that detects if a migration is needed, and generates the code and edmx into the migrations folder. This occurs when I first run the project after making model changes. I then recompile, including the new migration, which also updates the views, and when it starts up the second time, it applies the new migration code. This way I avoid all the issues with startup projects, and the powershell stuff not working correctly in VS2022. But that is just my workflow.

from c3d.msbuild.tools.ef6.generateviews.

gregveres avatar gregveres commented on June 15, 2024

Thanks for the info.

Are you saying:

  1. The process is not automatic if I am using code-first migrations?
  2. The process would be automatic if my DbContext and migrations were in the same project?

I could move the migrations into the Models project. They were in the main project by default when the application started before I started pulling parts into different projects. We just never thought about moving the migrations into the Models project. They seem to be more a part of the app rather than part of the model. But I could go either way.

from c3d.msbuild.tools.ef6.generateviews.

CZEMacLeod avatar CZEMacLeod commented on June 15, 2024

@gregveres 1) The process is not fully automatic. When using the extension, it wasn't either - you had to manually trigger the generate views command.
2) It could be more automatic if the migrations were in the DbContext project. I always assume that the models can go in a separate project, but that the context and migrations should be in the same project. I then have the app in a third project. Obviously, the models can be in the same project as the context if you don't want to fully break it up.

You can make it nearly fully automatic by creating the command line project to handle the model changes/migration creation and outputting the latest edmx file.

Technically the edmx associated with each migration is actually stored in the resx file as "Target" - it is a Base64 encoded GZip of the source. I guess it would be possible to add the step to pull the edmx from the migrations to the build task. I might have a look at adding that, or I would accept a PR ;)

from c3d.msbuild.tools.ef6.generateviews.

Related Issues (5)

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.