Constructing using parameterization with SqlParameter like this:
```C#
var paramDefinition = new SqlParameter("DefinitionId", System.Data.SqlDbType.UniqueIdentifier).Value = definitionId.ToString();
var query = $"SELECT * FROM [dbo].[{table}]";
var queryResult = await context.Blogs.FromSql($"{query} WHERE DefinitionId = @DefinitionId", paramDefinition).FirstOrDefaultAsync();
It will generate an error stating that it hasn't declared @DefinitionId.
It looks like you can disregard the specified parametername in SqlParameter as EF expects you to specify the paramters like @p0, @p1, etc:
```C#
var paramDefinition = new SqlParameter("DefinitionId", System.Data.SqlDbType.UniqueIdentifier).Value = definitionId.ToString();
var query = $"SELECT * FROM [dbo].[{table}]";
var queryResult = await context.Blogs.FromSql($"{query} WHERE DefinitionId = @p0", paramDefinition).FirstOrDefaultAsync();
Can you verify - or clarify what I did wrong in the first codesnip?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
This seems more like product issue rather than doc issue.
I had to test this locally as it looked right to me until I spotted:
var paramDefinition = new SqlParameter("DefinitionId", System.Data.SqlDbType.UniqueIdentifier).Value = definitionId.ToString();
You are setting the SqlParameter value on the same line as the paramDefinition declaration. This causes the paramDefinition variable to contain the int value 1, not the SqlParameter.
Changing it to the below fixes the issue:
var paramDefinition = new SqlParameter("DefinitionId", System.Data.SqlDbType.UniqueIdentifier);
paramDefinition.Value = definitionId.ToString();
From my testing locally, EF is doing everything right with parameters.
Most helpful comment
I had to test this locally as it looked right to me until I spotted:
var paramDefinition = new SqlParameter("DefinitionId", System.Data.SqlDbType.UniqueIdentifier).Value = definitionId.ToString();You are setting the SqlParameter value on the same line as the paramDefinition declaration. This causes the paramDefinition variable to contain the int value 1, not the SqlParameter.
Changing it to the below fixes the issue:
var paramDefinition = new SqlParameter("DefinitionId", System.Data.SqlDbType.UniqueIdentifier); paramDefinition.Value = definitionId.ToString();From my testing locally, EF is doing everything right with parameters.