MongoDbContext for data migration in EF core? - mongodb

Currently I'm trying to find a method to use EF core 2.2 for data migration. After reading the instruction at:
https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/
I realise that it only support DbContext.
At the moment, in my project I have mongoDBContext and IMongoDBContext for my database and I couldn't find any package that support them. I also try using Microsoft.EntityFrameworkCore.Design but it's not helping. Is there any solution for me to use mongoDbContext as the database provider, or any packages that support mongoDB as the database provider?
As for my attempt to create a migration file despite not having DbContext:
From my terminal
dotnet ef migrations add InitialCreate
Error
No DbContext was found in assembly '.Data'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
Thank you so much!

MongoDb is schema-less storage.
Entityframework Migrations is use to update schema of the tables. Yes migrations can also run update/delete/insert part of migration but only because Sql is dependent on schema.
In addition EF is not supporting MongoDb since mongo db is not using sql, mongo db has his own api/language.
Yes recent updates of EFCore supports CosmosDb but only because CosmosDB can talk sql
To sum up.
If you need to modify schema probably your MongoDb design is wrong.
If you want to talk to MongoDb use https://docs.mongodb.com/ecosystem/drivers/csharp/
If you are not familiar with MongoDb use what you familiar with

Yes, Mongodb is shema-less storage. But a solution always has some sort of schema in your POCO/DDD typed/dynamic objects and related domain logic. And you may change these contracts over time. So with Mongo we have the ability to perform two types of migrations: upgrade scripts ( like with RDBMS) or on-the-fly document migration when documents are used. You definitely can use your MongoDB without changes in existing documents in projects like collections of metrics and IoT device data or highly dynamic objects but this is not always the case.

Related

Is it possible to set a TTL on CosmosDB container in EF Core's OnModelCreating?

In EF Core, OnModelCreating scaffolds the entire database, but I don't see a way via the model builder to define a TTL; It seems like I would have to delete the container that gets created by EF Core.
Does anybody know of a better solution?
Eoleary. Although there is full support for Entity Framework Core and Cosmos DB including the EF Core Azure Cosmos DB Provider with almost full support for the CosmosClientOptions Class. The TTL component will not be available until v. 6.0 dotnet\efcore nugget package at the earliest. You can track this through the following dotnet\efcore Git Issue: Cosmos: Configure TTL per entity/entity type/collection
Version 3.1.9 is GA and version 5 release candidate is here. Additional information can be found on the dotnet/efcore project repository.
It looks like this is possible now. https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/whatsnew#configure-time-to-live
modelBuilder.Entity<Family>(
entityTypeBuilder =>
{
entityTypeBuilder.HasDefaultTimeToLive(100);
entityTypeBuilder.HasAnalyticalStoreTimeToLive(200);
});

What is a good action plan for database first connect data from postgresql to a c# project with dot net core and using entity framework core

I need to successfully do database first connect data from postgresql to a c# project with dot net core and using entity framework core.
Am familiar with mvc with sql and entity framework full database first (in this case we use the Entity Data Model Wizard which makes things easier.
I am not familiar with EFcore, dot net Core and also postgresql.
I successfully did a code first connect data from postgresql to a c# project with dot net core and using entity framework core, and using npgsql, on a console app.
Now I need to do database first web application, and should I try to edit my existing code first console app to try database first? Or should I build a new mvc project from scratch?
Also, if I do from scratch, what will be a good sequence I try
eg 1. try entity framework core tutorial first (which uses sql and is only code first),
then2. try to see how to do database first using reverse engineering
then3. try to replace the sql with postgresql
or are there any other methods that are better?
Scaffolding works with postresql.
Create project which will have your database entities and context. Install efcore tools and npgsql for this project.
Then, inside new project try this command using cmd:
dotnet ef dbcontext scaffold "Host=localhost;Database=databaseName;Username=user;Password=password" Npgsql.EntityFrameworkCore.PostgreSQL -t table1 -t table2 -o outputFolder
You dont have to pass -t parameters if you want to scaffold whole database.
If some error happens, try --force argument.
You should be able to use this database via context created by ef core.

Does Phinx help in query building

I'm trying to use PHINX as database query builder for SQL database. Does Phinx help only database migrations?
The document also has only about configuration and steps for migration.
https://phinx.org/
http://docs.phinx.org/en/latest/
From the documentation you posted:
Phinx is just about migrations without all the bloat of a database
ORM system or application framework
PHP has many options for ORMs, such as Redbean, Doctrine and my favorite, Eloquent (comes with Laravel)

Executing raw SQL using EntityFrameworkCore and SQLite on .NET Core

I am working on some security illustrations and therefore need to purposefully write insecure SQL queries.
The environment I am looking at is .NET Core (not full .NET), the driver used is EntityFrameworkCore and the database type is SQLite.
Regular connections using the built in lookup and query functions work without any issue. However there seems to be no function that would allow me to execute a raw SQL statement.
Several online resources recommend using the .FromSql() and .SqlQuery() methods on the database / context, but neither of these methods seems to exist in the .NET Core driver.
Is there any way to execute a raw SQL query in this setting?
As pointed at comment:
Check if there is Microsoft.EntityFrameworkCore.Relational reference on your project references(if you use sqllite it should be in the Microsoft.EntityFrameworkCore.Sqlite reference).
You could use the Nuget Package:
Microsoft.EntityFrameworkCore.Sqlite
and
db.Database.ExecuteSqlCommand("YOUR SQLITE SQL COMMAND");
where db is an instance of a class derived from DbContext

migration existing schema of titan db

Need help in migrate existing titan DB instance ,schema with data to another running titan DB instance in another server .
We created Titan DB instance (schema) using 0.5.4 version.
Is there any API provided by titan for migration ?
Thanks in advance
There are no push-button migration utilities in the Titan API. Most of the time, users write migration scripts in groovy to do data migrations. This might entail use of titan-hadoop in 0.5.4 or BLVP in Titan 1.0. In your situation, it doesn't sound like you need any of that. Just copy the data files of berkeleydb from your original server to your new server.