Entity Framework Core: How to get the Connection from the DbContext?

前端 未结 1 655
情书的邮戳
情书的邮戳 2021-02-02 07:30

I am trying the new Entity Framework Core with MySQL Connector.

I can get a valid DbContext and write into the database so everything has been setup correc

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 07:56

    The Microsoft.EntityFrameworkCore.Relational (https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Relational/) package provides extension methods for this - you can use dbContext.Database.OpenConnection() or dbContext.Database.GetDbConnection() to get the DbConnection object.

    Note: if you have Microsoft.EntityFrameworkCore.SqlServer installed then you don't have to explicitly install this package

    0 讨论(0)
提交回复
热议问题