问题
I have tried the below
var p = new SqlParameter("Option", "AUTHENTICATE");
var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option", p).ToList();
var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option=@Option", p).ToList();
and
SqlParameter[] ps = new SqlParameter[1];
ps[0] = new SqlParameter("Option", "AUTHENTICATE");
var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option", ps).ToList();
var user = _context.Set<User>().FromSqlRaw("EXECUTE dbo.spGeneral_Authenticate @Option=@Option", ps).ToList();
Error:
InvalidCastException: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.
回答1:
InvalidCastException: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.
For the above error, SqlParameter should be Microsoft.Data.SqlClient.SqlParameter not System.Data.SqlClient.SqlParameter
来源:https://stackoverflow.com/questions/58146172/how-to-use-stored-procedures-with-sqlparameters-in-ef-core-3-0