Reputation: 65
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
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
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
Upvotes: 1
Views: 3060
Reputation: 1348
The replacement for Query<T>()
is Set<T>()
.
So following your example it'd be something like this:
lst = await context.Set<Authenticate>().FromSqlRaw(sqlQuery, usernameParam,passwordParam).ToListAsync();
Upvotes: 4