Ausführend mit SQLParameter erstellt nicht die erwartete SQL [Duplicate]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Ausführend mit SQLParameter erstellt nicht die erwartete SQL [Duplicate]

Post by Anonymous »

Dies ist mein C# Code: < /p>

Code: Select all

if (country != null)
{
Query += " AND Users.Country IN (N'";

for (int i = 0; i < country.Count; i++)
{
Query += i == 0 ? $"@country{i}'" : $", @country{i}";
}

Query += ")";
}

context.Database.ExecuteSqlCommand(Query, new SqlParameter($"@country0", "de"));
< /code>
Dies ist der produzierte SQL: < /p>
exec sp_executesql N'INSERT INTO [table] (table.column1, table.column2)
SELECT 5002, table.column
FROM table2
LEFT OUTER JOIN table3 ON table2.column = table3.column
WHERE 1 = 1
AND table3.Country IN (N''@country0'')', N'@country0 nvarchar(2)', @country0 = N'de'
< /code>
Wenn ich die SQL manuell in < /p>
 ändere, ändere ich manuellexec sp_executesql N'INSERT INTO [table] (table.column1, table.column2)
SELECT 5002, table.column
FROM table2
LEFT OUTER JOIN table3 ON table2.column = table3.column
WHERE 1 = 1
AND table3.Country IN (N'de')', N'@country0 nvarchar(2)', @country0 = N'de'
Ich frage mich also, warum es das erwartete SQL nicht ersetzt/generiert. Name.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post