Not able to add migration and updating database in dotnet core ef - entity-framework-migrations

I am using generic DesignTimeDbContextFactory in Dotnet core 2.2.1 version for database.
I am trying to add migration for which, a class created under the migration folder but didn't reflect the changes in UP and Down and also in ContextModelSnapShot file.
if I try with dropping ContextModelSnapShot, then changing reflected. but the issue here is it will build a table but also dropping the table in DOWN.
Can anyone help me to come out through this issue?

In my case, the problem is the previous changes file is exists which already did by the previous developer who is working on it. I just temporary remove that file from the migration folder for that particular context as i have multiple contexts in my app and try to do migration will work for me. it was conflicting with the previous files.

Related

CoreData migrations without versioning

Right now I use versioning to make any changes in a database. But it brings some problems. For example it's hard to merge a feature branch with a new db version into a master/dev where somebody also added a new version.
So my question:
Is it safe to change db in a single xcdatamodel without adding new versions? I tried so and it works but everywhere on the internet I see warnings that you must not do that.
iOS9+.
I found this: https://stackoverflow.com/a/37264096/5328417 but it's without a proof
As #pbasdf noted, since iOS 9 you can do a lightweight migration without adding any new model version. Source model (previous model version) is cached to store and used as a last ditch effort during lightweight migration.
I am using this feature in my own apps successfully. Although I was not able to find this documented. Just that WWDC video (18'15 Model Caching) mentioned. This is exactly the reason why Core Data is so mysterious sometimes..
If your app is in development stage then you may use one model without versioning.
But if it is release on the App Store then you have to create the versions when you make changes (such as adding a new attribute, adding a new entity, renames attributes etc.). Otherwise, Core Data won't perform lightweight migration.

Entities cannot be found after update edmx file

For the project I am working on, we have updated the database with two extra datatables that I now would like to add to the edmx file, but this gives an unwanted result.
What I do is open the edmx file, open the model Browser and run Update form database. In the wizard here I choose the two tables I want to add under the add tab and click finish.
The tables show up in the diagram view and in the Model browser under Model.Store-Tables/Views (and under Entity Types and EntityContainer). So far so good.
When I then save the changes to the edmx, all other existing entities,as well as the complete content of the Model.Context.tt file are deleted. The result being that the context entity and all underlying entities no longer can be found.
I do not understand why this is happening, and I don't know how to fix this and I am now stuck in the development of the project. i am using VS2015 and Entity Framework 6. I have spend most of the day to find a solution, but have not been able to do so. None of the "Entity can't be found" solutions around fixed my problem. I hope therefor that some smart minds here can help.
Thans!

App_Data folder is not checked in with Team Foundation Server [duplicate]

I am working with ASP.NET C# MVC 5.
.mdf/.ldf files in App_Data do not appear on Pending Changes in team explorer. Therefore I can't check them into TFS(visual studio online). I've tried recreating the project a few times and none worked. What might be the cause for this?
Go to Team Explorer and locate Excluded Changes and you should find it excluded. Right click the App_Data folder and include it.
But you might want to reconsider including the database files. As you're developing and testing, every little database interaction will trigger a change and most of those are trivial. Also, if someone else is working on this project, they may not want your database file to overwrite theirs when they Get Latest Version.
If you're using Entity Framework Code-First, the database is automatically generated when you build the project I believe, otherwise you just run the Update-Database command to do it. This lets everyone collaborating have their own local database file to work with. You can also utilize migrations to make updates to the database structure. If you want the database to be generated with pre-populated data, you should utilize the Seed method.
This is a general question. As already answered by 'Ty Morrow' in above comment there is an initial Seed Method in Entity Framework which ensures that all values are inserted. However there are many scenarios that you also need to work with the latest added / removed DB entries not present in the seed method.
Please perform the following steps to ensure that your data directory file is included in the source control.
Click App_Data folder and on encircled toolbar click on Show All Files as shown below in the snapshot
Right Click on your MDF (Data Source) File and click on Include in Project
Right Click again on your MDF File and click on Include in Source Control
Simply Check in the file by Right Clicking on root project folder link and file show be now part of Source Control

The item $/MyTeamProject/Main already exists

So I have been messing around creating and deleting (read destroying via TfsDeleteProject) in preparation for something I have to do in production soon.
When I try to recreate the sample team project with the same name I have no problem but when I try to re-create the same structure (i.e. creating the Main folder) I get the error in the title of this post:
"The item $/MyTeamProject/Main already exists."
I have tried deleting the team project, clearing my local tfs cache and reopening VS but each time when I try to create the Main folder I get the error.
So something is not getting deleted. Any ideas?
EDIT: I wanted to point out as well that I have removed the physical folders on my local system as well.
Not exactly intuitive because I clearedmy local tfs cache (multiple times) BUT...
After my latest repeat of the steps above (definition of insanity) I decided to do a Get Latest on the team project.
I was then able to re-create the Main folder.

Removing CoreData migrations used in development

We developing a iOS app that uses CoreData. To keep ourselves from going crazy and having to delete the app every time we make a change to the models, we have been using lightweight migrations. At this point we have about 30 or so migrations and are getting ready to submit for review.
Looking at the .ipa file it looks like all of these migrations exist in there as separate files. I was wondering if there is any easy way to collapse all of these migrations into a single model file now that we are done with development and ready to ship 1.0.
A colleague of mine figured it out so I thought I would share it here.
Open the project and right click on the .xcdatamodeld, and delete it (just the references) from the project
Open the finder and find the .xcdatamodel, right click on it and show contents of package
Delete all of the migrations that you don't need
Go back into Xcode and add in the root .xcdatamodeld into your project
Test
Commit your changes
Done.
Anyone doing this I would highly recommend making a backup (or using version control such as git) to protect yourself against inadvertent mistakes.
I am sure glad not to have to ship 30 odd dev migrations to our 1.0 customer!!!

Resources