0

I have an ASP.NET Core application in which I'm using EF Core with MSSQL. In one table of used db there's a column with around 2MB binary data values. Instead of materialising it in memory I'd like to stream that data to the user, so it won't end up in the LOH (Large Object Heap). I've found out that in order to do that I can use ADO.NET as it supports column values streaming.

Most of the time I'm perfectly happy with using EF Core, but in this one case I'd like to fallback to ADO.NET. I know EF Core nowadays depends on Microsoft.Data.Sql instead of System.Data.Sql, so when I found GetDbConnection() (provided in Microsoft.EntityFrameworkCore.Relational assembly) method I expected its return type to be Microsoft.Data.SqlClient.SqlConnection which would play nicely with Microsoft.Data.SqlClient.SqlCommand constructor, but in fact what I'm getting is System.Data.Common.DbConnection.

The question is it possible to transform System.Data.Common.DbConnection (which I'm getting from EF Core) into Microsoft.Data.SqlClient.SqlConnection (which I want to consume using Microsoft.Data.Sql)?

2 Answers 2

5

Ok, I'm embarassed. Turned out when using Sql you can just cast it directly and it works.

var mdsSqlConnection = (Microsoft.Data.SqlClient.SqlConnection)_dbContext.Database.GetDbConnection();
Sign up to request clarification or add additional context in comments.

Comments

0

var mdsSqlConnection = (Microsoft.Data.SqlClient.SqlConnection)_dbContext.Database.GetDbConnection().Connectionstring;

but password of BD missing in this string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.