Skip to content
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

Add function to Init Migration #13952

Closed
ghost opened this issue Nov 14, 2018 · 6 comments
Closed

Add function to Init Migration #13952

ghost opened this issue Nov 14, 2018 · 6 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@ghost
Copy link

ghost commented Nov 14, 2018

Hello, I want to create an initializing migration to which functions have already been added. It’s inconvenient to manually add to the migration file because during the development phase it is often necessary to initialize the database again and again. To keep for the sake of this a migration file that also changes very often does not make sense. Tell me what solutions there are to insert the sql code (in particular, the function creation code) into the generated migration file.

@ajcvickers
Copy link
Member

@bricelam to respond.

@bricelam
Copy link
Contributor

bricelam commented Nov 14, 2018

@terrainkognito2017 It doesn't sound like you're getting much value from using Migrations at this stage of development. Have you considered using using code like this instead? (Use Drop-Database to have the schema recreated when your model changes.)

context.Database.EnsureCreated();
context.Database.ExecuteSqlCommand("CREATE FUNCTION...");

If you really want to use migrations, you could start with an empty migration. Comment out any DbSet properties and the OnModelCreating method, add the initial migration. Add your functions to that migration. Finally, uncomment your DbSets and OnModelCreating. This lets you easily replace your second migration (using Remove-Migration, Add-Migration) while keeping the function code around.

@bricelam
Copy link
Contributor

Issue #3053 is also about creating a better schema management workflow for the early stages of a project.

@ghost
Copy link
Author

ghost commented Nov 15, 2018

My task is to make the functions be added to the initial migration file Init.cs when calling the Add-Migration Init

@ghost
Copy link
Author

ghost commented Nov 15, 2018

And how can I use the functions I created from the context, besides using https://docs.microsoft.com/ru-ru/ef/ef6/querying/raw-sql

@ajcvickers
Copy link
Member

@terrainkognito2017 As far as we understand your question, there isn't a way to do exactly what you are trying to do, and it's not something we are planning to implement. Given this, @bricelam Is suggesting some other ideas that might solve your originally stated problem in a different way.

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Nov 16, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

2 participants