Update database migration using CLI on a mac [closed] - c#

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last month.
Improve this question
I just downloaded a project with Entity Framework installed; the difference with my co-workers is that I'm using a Mac.
I created a docker container for the database, and someone sent me a backup of the database, so I have the database restored and working with the project.
Someone created a new database migration, so I pulled the changes and needed to run the update database command. So I need to use the CLI version because it does not have the Package Manager Console.
So I try to run: dotnet ef database update 20221229175926_addSalariesTable
But this is returning:
Unable to create an object of type 'MyContext'. For the different
patterns supported at design time
My project consists in two layers, one for the web and the other for models and data
Web project name: Web
Data project name: Persistence
How can I run the update migration correctly?

You will need to navigate to the directory that contains your data project (Persistence) in the command line and execute the following command:
dotnet ef database update 20221229175926_addSalariesTable --project Persistence --startup-project Web
This command tells the Entity Framework to update the database using the migration with the specified name and to look for the migration files in the Persistence project.

Related

Trouble connecting to local SQL server database with Asp.Net Core

Just downloaded the vs community edition 2019 version 16.7.7 and it flag off an error saying couldn't download microsoft.net.4.7.targetingpack/resources however I launched the vs community 2019, started a asp.netcore web application and wrote a single class and scallfolded a controller with a CRUD view but my problem is I can not connect to the database.
My connection string is fine at the appjson setting also my startup.cs because I have checked all the suggestions offered here, and I implemented them! Please help! Is my vs-2019 corrupted.
I want to say thank you everyone for listening to me, however I figured out that I didn't generate a database creation code by enabling migration and adding a migration which will do that automatically and save a snapshot schema that will be used to create the actual database in the database management environment. Please that was my mistake. Add migration and update database and your good to code some more

Data in database is not visible despite migrations

I have a project that I developed with Asp.Net MVC5. I created the database of the project with the CodeFirst approach. When I finished I uploaded my project to github.
However, after downloading the project from github and saying "enable -migrations" and "update-database", the data in my tables is not coming.
If my internship teacher wants to test this project on his computer, he will create the database, but he will have problems because there is no data in the tables. How can I solve this problem?
You could use code first migrations to seed the database. See link for more information on it. Documentation This should make your database start with data.

Is it possible to edit a project once is published on Azure?

I'm testing an application I just published using the free option that Azure gives us.
In this process I found out that I need to make a change to a Controller (ASP.NET Core 2.0) and I've been looking for the options to do so.
I've encountered with Azure App Service Editor and I'm reading some documentation about it. However, it does not seem the way to do this kind of change since I can't access the *.cs files thru this service. This is the list of files that are shown:
So, my question is:
Is there a way to edit these files (controllers, views) with Azure App Service Editor?
If no, what would be the way to reflect this changes on my already published application? Also, in the case the answer is "republish the project", is it possible to do so without alter the information contained in the database that has been added during this test process and only update the modified files?
I apoligize if these questions are very basic but I'm just getting started to know about Azure. Thanks in advance.
How I publish it:
In order to publish this project I used the option Visual Studio gives us:
Now, if I go to the same option, this windows shows up:
Question: If I hit the 'Publish' button I believe it will republish, the whole project, correct (the database included)? If this is the case, I believe there will be conflicts about the databases, since I have already information in the project published and other information in the local project. Is it possible to reflect the update for everything but the databases?
No, you can't update the files there as this is a compiled web app, so you have to publish the update.
I'm assuming you're using EntityFramework and originally publishing the database via the web publish.
If you click "settings" on the publish dialogue, on the second page (settings tab) you'll see the options for publishing the database.
Here you'll see options as to whether to update the database during deployment, this I believe is to apply migrations. But if you uncheck these it should not update your database at all.
You should verify this after saving the publish by looking at the generated publish profile (you don't have to do a publish to see this)
It will be located at "YourApp\Properties\PublishProfiles" and should have been added to your solution, and will be called something like "Your App - Web Deploy.pubxml"
Within this you will see a <PublishDatabaseSettings> section, where the Enabled properties should be set to False
However I would advice that before publishing any update:
Test the deployment to a new server
Back up the database before deploying and test you can restore from it.

C# publish desktop project with database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a school project where I have to build a desktop application in C# with ASP.NET MVC 5.Im using Visual Studio 2015, and Sql Server.
That application contains a small database with about 5 tables and some data. The project is done and it works fine on my computer. My problem is: part of the task is making the program I made work on another computer.
How do I publish my application? Publish with One-Click makes the installer, but, when I do install the software in another computer, it gives an error that it cannot connect to the database. How can I deploy my project WITH the database to another computer?
Thanks in advance
EDIT 1:
After an long search, i found an youtube video that explains how to do a Setup Project using Visual Studio 2015, where you can choose what you need to install and the configurations you need to adjust. I´m still trying to make it work, but i can fell im at the right path finally.
Youtube video: https://www.youtube.com/watch?v=zx6w3BDD6Sg
What database are you using?
File-based databases like SQLite or SQL Server Express are built to store their data in easily transportable files that can be shipped along with your app/site.
If you're using a server-based database like SQL Server, MySQL, etc., you'll need to ensure that the target machine/environment has the same database server installed and you'll need to write a deployment script that attaches pre-populated data files to the server. This may be a lot more work.
Try with using Sqlite as a database with entity framework code first approach with that you can hold the database in user's computer (c:/users/username/appdata). By code first approach you can create the database while the user install the application and you can drop the database while user uninstall the application.

How to add a portable database to an MVC application?

I currently have an ASP.NET MVC 3 project, plus a class library project, that I am planning on open-sourcing. Before I do that though I want to clean up the project a little bit. One modification I want to make is with the database. Currently the site is published to a shared hosting server and I setup the SQL database on that server. However, since people will be forking the project and running it locally I'd like to just attach a SQL server express database or something that is part of the project. I want people to clone the repository, open the project, press F5 and have it run. Currently they'd have to setup a SQL database and create all the tables and stuff.
The solution consists of two projects: MvcUI and Domain. Domain is where all the application logic occurs. In fact, the domain is UI agnostic which means that it could be consumed by a desktop application just as easily as it could be by a web application.
I would like the database to be part of the Domain (class library) project. I have never done this before. If anyone could provide a simple explanation for how I would need to go about setting this up I would be thrilled. It would be very nice to have the database just be a in the solution because I could pre-populate it with some basic data. What do I need to do to get this database in my project as a database file or what not?
SQL Server Compact Edition is a portable SQL database that should do exactly what you are asking.
Microsoft SQL Server Compact 4.0 is a free, embedded database that
software developers can use for building ASP.NET websites and Windows
desktop applications. SQL Server Compact 4.0 has a small footprint and
supports private deployment of its binaries within the application
folder, easy application development in Visual Studio and WebMatrix,
and seamless migration of schema and data to SQL Server.

Categories

Resources