Pomelo.entityframeworkcore.mysql: Pomelo.EntityFrameworkCore.MySql๋กœ ๋ชจ๋“  ํ…Œ์ด๋ธ” ์ด๋ฆ„์„ ์–ป๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

์— ๋งŒ๋“  2020๋…„ 12์›” 24์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: PomeloFoundation/Pomelo.EntityFrameworkCore.MySql

์ผ๋ถ€ ํ…Œ์ด๋ธ”์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ํ…Œ์ด๋ธ” ์ด๋ฆ„์„ ์–ป๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

CreateCommand ()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ • ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๊นŒ?

closed-question type-question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์–ด ์˜ค, ๋ชป ํ•  ์ˆ˜๋„ ์žˆ๊ฒ  ๋„ค์š”. 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;
    }
}

}
```

๋ชจ๋“  4 ๋Œ“๊ธ€

์˜ˆ, 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;
    }
}

}
```

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰