简体   繁体   English

.NET Core 3.1 - EntityFrameworkCore - DBContext.Query 已过时

[英].NET Core 3.1 - EntityFrameworkCore - DBContext.Query obsolete

I find many examples and tutorials where functions are obsolete, but it's hard to find replacements for them我发现许多函数已经过时的示例和教程,但很难找到它们的替代品

here is an examble, the Query function is obsolete, yet I cannot find what to use in it's place这是一个示例,查询 function 已过时,但我找不到在它的位置使用什么

SqlParameter usernameParam = new SqlParameter("@username", usernameVal ?? (object)DBNull.Value);
SqlParameter passwordParam = new SqlParameter("@password", passwordVal ?? (object)DBNull.Value);

string sqlQuery = "EXEC [dbo].[LoginByUsernamePassword] @username, @password";

lst = await context.Query<Authenticate>().FromSql(sqlQuery, usernameParam,passwordParam).ToListAsync();    

in this case, this line does not compile:在这种情况下,这一行不会编译:

lst = await context.Query<Authenticate>().FromSql(sqlQuery, usernameParam, passwordParam).ToListAsync();

context beeing a DbContext instance作为DbContext实例的上下文

anyone knows how to fix this?有谁知道如何解决这个问题?

I have checked the microsoft doc, it says it's obsolete but does not point to it's replacement我检查了微软文档,它说它已经过时但没有指出它的替代品

The replacement for Query<T>() is Set<T>() . Query<T>()的替代品是Set<T>()

So following your example it'd be something like this:所以按照你的例子,它会是这样的:

lst = await context.Set<Authenticate>().FromSqlRaw(sqlQuery, usernameParam,passwordParam).ToListAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在事务内使用DbContext.Query - Cannot Use DbContext.Query inside a transaction 如何在 .NET Core 应用程序中使用 EntityFrameworkCore 模拟 DbContext - How to mock DbContext using EntityFrameworkCore in .NET Core application 在ASP.Net Core 1.0中注册通用EntityFrameworkCore DbContext - Register generic EntityFrameworkCore DbContext in ASP.Net Core 1.0 .NET Core 3.1 / .NET 5.0 中的 System.Security.CodeAccessPermission 是否已过时? - Is System.Security.CodeAccessPermission obsolete in .NET Core 3.1 / .NET 5.0? 如何从 ASP.NET Core 3.1 中的 EntityFrameworkCore 3 中删除依赖项 - How to remove dependency from EntityFrameworkCore 3 in ASP.NET core 3.1 .Net核心和EntityFrameworkCore - .Net Core And EntityFrameworkCore Scaffold-DbContext SQL 视图? ASP 网络核心 3.1 - Scaffold-DbContext SQL Views ? ASP NET CORE 3.1 无法为 Net Core 3.1 WPF 应用程序创建类型为“DbContext”的 object - Unable to create an object of type 'DbContext' for Net Core 3.1 WPF app ASP.NET Core 2 无法解析 Microsoft EntityFrameworkCore DbContext 类型的服务 - ASP.NET Core 2 Unable to resolve service for type Microsoft EntityFrameworkCore DbContext Scaffold-DbContext 失败。 System.TypeLoadException:无法在 .NET Core 上加载类型“Microsoft.EntityFrameworkCore.Internal.ProductInfo” - Scaffold-DbContext Fails. System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.ProductInfo' on .NET Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM