Type of issue
Code doesn't work
Description
The sample code for FromSqlRaw doesn't work.
var columnName = "Url";
var columnValue = new SqlParameter("columnValue", "http://SomeURL");
var blogs = context.Blogs
.FromSqlRaw($"SELECT * FROM [Blogs] WHERE {columnName} = @columnValue", columnValue)
.ToList();
It produces a runtime error
System.InvalidCastException: Unable to cast object of type 'Microsoft.Data.SqlClient.SqlParameter' to type 'Microsoft.Data.Sqlite.SqliteParameter'.
Here the type SqlParameter is incorrect. It should be a provider specific type, say SqliteParameter for SQLite, NpgsqlParameter for Npgsql.
Page URL
https://learn.microsoft.com/en-us/ef/core/querying/sql-queries?tabs=sqlserver
Content source URL
https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/querying/sql-queries.md
Document Version Independent Id
98b01ef5-24a5-5f59-30c9-af264f739815
Article author
@smitpatel
Type of issue
Code doesn't work
Description
The sample code for
FromSqlRawdoesn't work.It produces a runtime error
Here the type
SqlParameteris incorrect. It should be a provider specific type, saySqliteParameterfor SQLite,NpgsqlParameterfor Npgsql.Page URL
https://learn.microsoft.com/en-us/ef/core/querying/sql-queries?tabs=sqlserver
Content source URL
https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/querying/sql-queries.md
Document Version Independent Id
98b01ef5-24a5-5f59-30c9-af264f739815
Article author
@smitpatel