How to use ef6.exe - entity-framework-6

I'm a newbie in entity framework. I have seen examples of using migrate.exe or enable-migration etc.
But migrate.exe does not exist any more. I explored the web and found that ef6.exe replaced the old migrate.exe
so I tried
ef6 -contexttypename musicstoredatacontext
ef6 -context musicstoredatacontext
nothing worked
I cannot find further support/documentation regarding the migration commands. and i'm new to migration.
Can somebody give me some hint how to work on it?

"If you execute Update-Database -Verbose inside Visual Studio's Package Manager Console, it will show you the call it uses to ef.exe to apply migrations." -Brice Lambson
It will be something like:
<PATH_TO_EXE>\ef6.exe database update --connection-string "<CONNECTION_STRING>" --connection-provider System.Data.SqlClient --verbose --no-color --prefix-output --assembly <PATH_TO_DLL> --project-dir <PATH_TO_PROJECT_DIR> --language C# --data-dir <PATH_TO_APP_DATA> --root-namespace <NAMESPACE> --config <PATH_TO_WEB_CONFIG>
Some of the arguments above can be omitted.
You can use the same strategy to determine how to create a migration (Add-Migration) with ef6.exe.
SOURCE: https://github.com/dotnet/ef6/issues/1365#issuecomment-540067758

use the command help to get the docs
ef6 --help
or
ef6.exe migrations --help

I succeeded in adding migration by updating powershell and use add-migration initial command
Reference can be found here.
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

Related

EF Core Migrations in Separate Project - Issues

I am not successful in adding ef core migrations in a separate project. I have provided the project structure at the end.
The DbContext class and the migrations are in separate projects such that the former is a class library and the migrations project is a console application. I added a reference to the DbContext project in the migrations project however, I am getting errors while running migration commands
\EF.BlogsDb.Migrations > dotnet ef migrations add InitialCreate --project EF.BlogsDb.Migrations.csproj
No DbContext was found in assembly 'EF.BlogsDb.Migrations'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
I followed advise from this link but I am not sure of the following.
In which project should i add these lines? is it the migrations project or my web project or the DbContext project?
options.UseSqlServer(
connectionString,
x => x.MigrationsAssembly("MyApp.Migrations"));
Why should i Add a reference to the migrations assembly from the startup assembly?
From which location/folder/project should i run this command?
dotnet ef migrations add NewMigration --project MyApp.Migrations
I can share the source code if you can tell me how to do that.
Thanks in advance for the clarifications one might provide!
Here is my project structure looks like:
The issue is solved using the following command.
dotnet ef --startup-project ../Project.Api/ migrations add InitialModel
Here I am using separate folder for the api and the EF.
Run the above command from the EF project folder
Start up project means referred to the api

Entity Framework migrate.exe not working after updating to AspNet.Identity

Since updating my solution to use ASPNET Identity instead of the old membership, the migrate.exe commando to update database schema stopped working. The only major change is that my Context now inherits from a IdentityDbContext, when before it inherited from a DbContext.
Everything works fine running update-database on package manager console, but using migrate.exe on the command line doesn't work anymore. I get the error:
System.Data.Entity.Migrations.Infrastructure.MigrationsException: No migrations configuration type was found in the assembly 'SampleProject.Repository.EF'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
I have a Configuration.cs file for the migrations, as always had and when running the "enable-migrations" suggested I get a message saying that migration are already enabled for the project.
Does anyone knows what the problem might be?
Thanks
Just a quick update on the solution.
It was DLL version conflict when running migrate.exe.
I was using the output from my web project (which also contained DLL for the EF project).
I updated it in order to use the bin content of my EF project and it worked just fine.

Run Migrations command if not have visual studio

I'm publishing a website ASP.NET MVC and get this error:
“Migrations is enabled for context ‘Context’ but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the ‘Update-Database’ command from the Package Manager Console.”
I can't install visual studio on server so i can't run ‘Update-Database’ command.
How to solve this problem ?
Find migrate.exe (YourApp\packages\EntityFramework.6.1.3\tools) and paste it in bin folder on the server.
Open Command Prompt on the server.
Run below commands
cd "C:\Websites\YourApp\bin" migrate.exe YourAppName.Api.dll /startupconfigurationfile:..\Web.config /verbose
Please Note that YourAppName.Api.dll should be the DLL having Enabled Migration.
you do not need to install visual studio on the server.
if you have your database connection string setup in web.config you should be able to run update-database in the package manager console and it will update your database on your web host.

Why can't the TFS command line tool find my project?

I'm using the TFS command line utility, "tf.exe" This command:
tf.exe dir /folders /server:[my server] /login:[my login] $/WebSite
Always returns this:
No items match $/WebSite
I know for a fact that my project exists and is called "WebSite". I can browse it fine from Visual Studio, so I know I have permissions to it.
Why would the command line utility not find it?
(It is part of a project collection. Would this change the naming of the project?)
I figured it out. Project collections are added to the end of the server name, which I wasn't doing.

How to integrate a Liquibase migration into my grails build?

I have a Liquibase migration that I manually run to load seed data from several CSV files into my database. I would like to run this migration each time I run grails run-app.
I think I have two questions in one:
How to I integrate the migrate
command into my grails run-app ?
How do I clear the DATABASECHANGELOG
to allow me to run the same
migration over and over?
Or, is there a better way to load a lot of data into a DB from CSV files?
Question 1 - To integrate migrate command into run-app, you should listen for events thrown in run-app scripts. This is explained here, and a more complete article is here.
Question 2 - For clearing the database, perhaps you can write a migration that clears the db for you? The way I do it is use a little script I wrote that just drops and creates a db. It's for MySQL:
target(dropdb: "The description of the script goes here!") {
def x = 'mysql -u root --password=XXXX -e "drop database yourdb; create database yourdb default character set utf8; " '.execute();
x.waitFor()
println "Exit Value ${x.exitValue()}"
}
setDefaultTarget(dropdb)
Question #2: If you have particular changeSets you want to run every time, there is an "alwaysRun" attribute you can set on the changeSet tag.
For my money, it's easier to read the Liquibase Gant scripts and replicate what they do. They're simple and you'll have more insight into what's happening.
You should use the autobase plugin. It will run your migrations when the application starts.
It has a script to convert from an xml changelog to a groovy one as well so you don't have to manually convert it.

Resources