简体   繁体   中英

General usage approach for EntityFrameworkCore DatabaseFirst by not scaffolding in C#.NET

I would like to deliver a C#.NET Core 6 application using EntityFrameworkCore 6 (EF6.Core) to a remote user, while the main intention of the application is to browse the entire MySQL server after authenticating the app to the MySQL server of the user for databases and tables including the records. The app should parse and list all available databases,then the user should select any of the listed databases and then the app should list all tables inside the database including the tables schema, once a table is selected the table records should be parsed and be available for further processing.

As I know there are some solutions recommending CLI methods such as 'dotnet scaffolding' or 'dotnet migrations' that I do find them not applicable to my case since following conditions are not fulfilled.

My requirements are (1) The user only gets the application executable and will not share the database structure and tables/schemas with the developer for integration.

(2) The user should not and will not execute the 'dotnet scaffolding' related commands on his machine to hand out the developer the schema of the database.

(3) The solution should be general and not specific since the application executable should not change and get tweaked for the use cases

Firstly, I would like to know whether EntityFrameworkCore 6 is advanced enough to meet the requirements or not.

Secondly any minimal runnable working C# code that could show how the task should be done is really appreciated.

Please consider that I am beginner with EF and I would like to read and understand a simple minimum runnable code that can shed some light on how to solve the problem.

By the way if EF6 is unable to accomplish the requirements is there any other suggested solution available?

The purpose of Entity Framework Core is to build a code model for a known database. Thus, it is a very poor fit for your application.

Instead, just use regular ADO.NET methods with a library such as MySqlConnector . You can use the DbConnection.GetSchema method to get a list of all schemas and tables (that your MySQL user account has permission to view).

using var connection = new MySqlConnection("Server=...;User=...");
connection.Open();

var databases = connection.GetSchema("DATABASES");
var tables = connection.GetSchema("TABLES");

// process the two DataTables retrieved above...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM