[英].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.