SQL Server Query DB to non entity type classes using EF Core

tquggr8v  于 2023-06-21  发布在  其他
关注(0)|答案(1)|浏览(145)

I have an ASP.NET Core 7 app with EF Core 7. I need to query some tables from a database which is not in my control, and I don't even have the dbcontext , but I have the connection string to the database.

I need to query some table from that database using EF Core 7 to some DTO which are not entity types. I have tried with Dapper and it works, but how to achieve the same thing with EF Core?

qyswt5oh

qyswt5oh1#

You can use my SqlQuery nuget library; https://www.nuget.org/packages/ErikEJ.EntityFrameworkCore.SqlServer.SqlQuery/7.0.0-preview1

var context = new ChinookContext();

var result = await context.SqlQueryAsync<MyDto>("SELECT * FROM MyTable");

相关问题