Entity Framework 6 (EF6) code first migrations with models in separate project - ef-code-first

Using EF6 code-first migrations, I am able to successfully save models and create new migrations for them. However, my DbContext class is in a Sharp.Data project, the actual (Sql CE) database lives under the Sharp.Server project bin folder, and my models live in a Sharp.Common project.
When I run add-migration -ProjectName Sharp.Data Migration3 (pointing to Sharp.Data as that is where the DbContext is), it successfully runs and identifies changes made to the models in the Sharp.Common project. However, when I run update-database -ProjectName Sharp.Data, it updates/creates/migrates/seeds a new database located under the bin folder of my Sharp.Data project, instead of Sharp.Server, where ultimately the application reads the data from.
Is there a way to do this? To have migrations generate/update a database that exists somewhere else besides its own project file? This may be a relic of using SQL CE, but it's my database of choice for various reasons.

You can pass extra parameters to update-database that allow to:
Specify a different connection string
Generate a SQL script that you can apply yourself to the target DB
Full syntax of Update-Database:
Update-Database [-SourceMigration <String>] [-TargetMigration <String>]
[-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>]
[-ConfigurationTypeName <String>] [-ConnectionStringName <String>]
[<CommonParameters>]
Update-Database [-SourceMigration <String>] [-TargetMigration <String>]
[-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>]
[-ConfigurationTypeName <String>] -ConnectionString <String>
-ConnectionProviderName <String> [<CommonParameters>]
To specify a connection string (which points to the correct folder in your project):
-StartUpProjectName and -ConnectionStringName, to specify a project that contains a .config file with a connection string with the provided name (1st syntax)
-ConnectionString, to specify directly the connection string (2nd syntax)
To create a SQL script that you can apply directly to the DB using other tool:
-SourceMigration: current migration in the destination DB -TargetMigration: migration to update to, and -Script: to generate a script taht you can apply by hand

#JotaBe's answer is correct. But to summise, you need to do the following:
add-migration "MigrationName" -ProjectName Sharp.Data -ConnectionString "ConnectionStringToYourTargetDatabaseHere"

Related

What command can I use to remove a project in .NET Core?

What command can I use to remove a project in .NET Core?
The project I want to remove was created with the help of the command:
dotnet new webapi
Is it true that there is still no command for this? It was pointed out here.
When you run the command dotnet new [type], dotnet will create a project in whatever folder the current working directory is. (where [type] will be something like console or webapi)
You never want to run this command without first creating a sub-directory and changing to it or you will have a mess of files sitting somewhere you will wish they weren't. The amount of files and their names will depend on the type of project you are making.
If you make this mistake and don't know which files to delete, you can delete them individually.
Create a temporary directory and change to it.
Run the same dotnet new [type] command in that directory.
Looking at the files created in step #2, you will know what to delete.
If you made a sub-directory to begin with, you can simply:
(windows)rd /s /q <dirname>
(linux)rm -rf <dirname>
to clean up the mess.

Visual Studio Team Services dotnet publish

My build completes with no errors, but it creates a randomly named zip file (s.zip) for the release step.
After the release step, I end up with that s.zip in inetpub/wwwroot/admin-tool/ folder. I'm almost there, but I want it to unzip and dump all the contents in here. This should be automatic, shouldn't it?
My dotnet publish looks like this:
and cause this to run, which is how I get the s.zip:
C:\Program Files\dotnet\dotnet.exe publish C:\agent\_work\3\s\Angular.AdminTool.csproj -c release --output C:\agent\_work\3\a\s
If I try to edit the -o argument and make it -o $(Build.ArtifactStagingDirectory)/admin-tool I will just end up with C:\agent\_work\3\a\admin-tool\s.zip
Is getting the name of my zip to be the same as the name of my web-site (admin-tool) the key to getting the zip to automatically extract in the release step?
In case it help others, I used the simple command line tools rather than the pre-canned "dotnet core" ones:
and for the Archive files task, be sure to include a hard-coded name for the zip to be used in the build process:
And for the release, in the "Deploy IIS App" task, be sure to include the full path for the zip file:
I also ran into this issue but solved it another way.
In my case I have a single project to build and deploy.
The $(Parameters.RestoreBuildProjects) value is set to a single project
MyProjectFolder/MyProject.csproj.
In the .Net Core Publish task, this value is used in the Path to Project(s) field.
Then I tick both the boxes for
I saved and queued this pipeline.
The zip file created seems to be derived from the name of the folder
so I ended up with a zip file in the artifact staging directory with the name of the project. Then the Publish Artifact task placed this zip file into the Artifact that is named in that task.

Why aren't my SQLite queries executing in my Qt Application

I have a Qt application which utilizes SQLite as a database. In the Qt Creator environment all my queries are executing perfectly and everything is fine but when i run the executable in my project folder no query is executing and i receive an error "No query,unable to fetch row". My database is open so i don't know what the issue is. Is there a reason for this?
You should place your SQLite database file alongside your executable. Also:
On Windows:
Place QtSql4.dll alonside your executable
place qsqlite4.dll in a folder named "sqldrivers" beside your
executable
These dll files are in your installed Qt Directory in bin folder.
On Linux:
Place libQtSql.so.4 alonside your executable
place libqsqlite.so in a folder named "sqldrivers" beside your
executable
These so files are in your installed Qt Directory in lib folder or in director "/usr/lib/i386-linux-gnu".

Execute liquibase update in production environment

I have a Java Maven project. I'm using liquibase to update DB.
Locally, to update my db, I just run in command line:
mvn liquibase:update
In production environment, I don't have Maven installed.
What I need to achieve is through console, execute a command to run the liquibase scripts in a specific classpath.
Any ideas?
Edit:
Ok.I'm trying to follow this approach. I put in a folder the following items:
liquibase jar
The war containing my application and the liquibase changesets
liquibase.properties: It contains the following:
url=jdbc:jtds:sqlserver://xxxxxxxx:xxxx/xxxxx
username=xxx
password=xxxxx
classpath=war_file.war
changeLogFile=WEB-INF/classes/sql/projectName/liquibase/liquibase.xml
Then, in a console, I execute:
java -jar liquibase-core-3.0.5.jar update
It works! It finds my liquibase.xml file and starts the liquibase update.
BUT, when it refers to liquibase.xml that are inside another jar file included in the lib, it fails, because I included it in the liquibase.xml as:
<include file="../other_module/src/main/resources/sql/projectName/liquibase/liquibase.xml" />
How can I add this "include" without doing "src/main/resources" and make it find this xml?
Running the updateSQL goal on your Dev machine:
mvn liquibase:updateSQL
You can generate a migration script:
└── target
└── liquibase
└── migrate.sql
This is one of my favourite features of liquibase. Sometimes clients insist that all database schema changes must be performed manually by their staff.
Another option is to build an auto-upgrade capability into your application. See the servlet listener

TeamCity MSbuild Deploy procedure

I'm using TeamCity for deployment process. For deploy i'm running MSbuild with this command line parameters:
/P:Configuration=Release
/P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=serviceUrl
/P:DeployIisAppPath=website
/P:AllowUntrustedCertificate=True
/P:MSDeployPublishMethod=WMSvc
/P:username=username
/P:Password=password
/P:SkipExtraFilesOnServer=True
/P:VisualStudioVersion=10.0
I have this parameter P:SkipExtraFilesOnServer set to true beacause i don't want MSbuild to delete some files which i have only on service enviroment, but don't have on my local project. But the problem is when i actually want to remove something from project (i have web application), i usually delete file from project, then i rebuild my app, and commit the changes in project file to source control, MSbuild leave this file on service because of this parameter.
MSbuild is using Release configuration, which i specified to use "all files in this project" to deploy. So the behaviour i want to implement:
TeamCity will leave all files which are not in my project reference list. (.csproj file).
TeamCity will delete files which were in .csproj but was deleted from it.
Please help me with that task.

Resources