์ผ๋ถ ํ ์ด๋ธ์ด ์กด์ฌํ๋์ง ํ์ธํ๊ณ ์ถ์ต๋๋ค. ๋ชจ๋ ํ ์ด๋ธ ์ด๋ฆ์ ์ป๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
CreateCommand ()๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ์ฉ์ ์ง์ ์ฟผ๋ฆฌ๋ฅผ ์ํํฉ๋๊น?
์, SHOW TABLES;
์ ๊ฐ์ ์ฌ์ฉ์ ์ง์ ์ฟผ๋ฆฌ๊ฐ ์๋ํฉ๋๋ค. ๋ฌธ์ ๋ ์ด๋ฌํ ๋ชฉ์ ์์ํ ๊ฒ์ด ์๋๋ฏ๋ก ์ถ๊ฐ ๋์์ด ํ์ํ๋ฉด Stack Overflow ์์์ด ์ง๋ฌธ์ ์์ฒญํ์ธ์.
@Flithor ์ง๋ฌธ์ ๊ฒ์ํ๋ฉด Stack Overflow์ ์ํ ์ฝ๋๋ก ๋ต๋ณ ํด ๋๋ฆฌ๊ฒ ์ต๋๋ค. pomelo-entityframeworkcore-mysql
ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ฉด ์๋ฆผ์ ๋ฐ๊ฒ๋ฉ๋๋ค (MySQL ๋ฐ EF Core ๊ด๋ จ ์ง๋ฌธ์ด๋ฏ๋ก ์ถฉ๋ถํ ๊ฐ๊น์ต๋๋ค).
์ด ์ค, ๋ชป ํ ์๋ ์๊ฒ ๋ค์. Stack Overflow์ ์ง๋ฌธ ์ ํ์ด ์์ต๋๋ค. -๋๋ฌด ๋ง์ ๊ฐ์ธ์ ์ธ ์ง๋ฌธ ...
(๋ค๋ฅธ ์ฌ๋์ ๋๊ธฐ ์ํด ์ ๋ชฉ์ ํธ์งํ๊ฒ ์ต๋๋ค)
์ด ์ค, ๋ชป ํ ์๋ ์๊ฒ ๋ค์. Stack Overflow์ ์ง๋ฌธ ์ ํ์ด ์์ต๋๋ค. -๋๋ฌด ๋ง์ ๊ฐ์ธ์ ์ธ ์ง๋ฌธ ...
@Flithor ์ด ๊ฒฝ์ฐ ์ฝ์ ๋ ์ํ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```c #
์์คํ
์ฌ์ฉ;
System.Collections.Generic ์ฌ์ฉ;
System.Diagnostics ์ฌ์ฉ;
Microsoft.EntityFrameworkCore ์ฌ์ฉ;
Microsoft.Extensions.Logging ์ฌ์ฉ;
Pomelo.EntityFrameworkCore.MySql.Infrastructure ์ฌ์ฉ;
๋ค์ ์คํ์ด์ค IssueConsoleTemplate
{
๊ณต๊ฐ ํด๋์ค IceCream
{
public int IceCreamId {get; ์ธํธ; }
๊ณต๊ฐ ๋ฌธ์์ด ์ด๋ฆ {get; ์ธํธ; }
}
public class Context : DbContext
{
public DbSet<IceCream> IceCreams { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseMySql(
"server=127.0.0.1;port=3306;user=root;password=;database=Issue1279",
b => b.ServerVersion("8.0.21-mysql")
.CharSetBehavior(CharSetBehavior.NeverAppend))
.UseLoggerFactory(
LoggerFactory.Create(
b => b.AddConsole()
.AddFilter(level => level >= LogLevel.Information)))
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
}
}
internal static class Program
{
private static void Main()
{
using var context = new Context();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var tableNames = GetTableNames(context);
Trace.Assert(tableNames.Contains("IceCreams"));
}
private static List<string> GetTableNames(DbContext context)
{
// EF Core will close the connection automatically for us, when we ensure, that it is EF Core itself that is
// responsible for opening the database connection. We can ensure that by calling `OpenConnection()` first.
context.Database.OpenConnection();
var connection = context.Database.GetDbConnection();
using var command = connection.CreateCommand();
command.CommandText = @"select `TABLE_NAME`
INFORMATION_SCHEMA
. TABLES
์ฌ๊ธฐ์ TABLE_SCHEMA
= database (); ";
var tableNames = new List<string>();
using var reader = command.ExecuteReader();
while (reader.Read())
{
tableNames.Add((string) reader["TABLE_NAME"]);
}
return tableNames;
}
}
}
```
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@Flithor ์ด ๊ฒฝ์ฐ ์ฝ์ ๋ ์ํ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
```c #
์์คํ ์ฌ์ฉ;
System.Collections.Generic ์ฌ์ฉ;
System.Diagnostics ์ฌ์ฉ;
Microsoft.EntityFrameworkCore ์ฌ์ฉ;
Microsoft.Extensions.Logging ์ฌ์ฉ;
Pomelo.EntityFrameworkCore.MySql.Infrastructure ์ฌ์ฉ;
๋ค์ ์คํ์ด์ค IssueConsoleTemplate
{
๊ณต๊ฐ ํด๋์ค IceCream
{
public int IceCreamId {get; ์ธํธ; }
๊ณต๊ฐ ๋ฌธ์์ด ์ด๋ฆ {get; ์ธํธ; }
}
INFORMATION_SCHEMA
.TABLES
์ฌ๊ธฐ์
TABLE_SCHEMA
= database (); ";}
```