首页 > 解决方案 > C# FromSqlRaw 与字符串列表

问题描述

我将 C# 的 FromSqlRaw 与 npgsql 一起使用,如何逃避我的List<string>此处以防止 SQL 注入攻击?以下代码不起作用:

int groupId = bundle.id;
List<string> joinItems = bundle.Scripts.Keys.ToList();

var validScriptBundles = Db.TableName.FromSqlRaw(
    "SELECT DISTINCT ON (ts.\"Filename\", ts.\"GroupId\") ts.* " +
    "FROM \"TableName\" ts " +
    "WHERE ts.\"GroupId\" = {0} AND ts.\"Filename\" IN ({1})", groupId, joinItems);

PostgresException:42883:运算符不存在:text = text[]

我不能 string.join 因为那会使我面临 SQL 注入攻击。

标签: c#postgresqlentity-framework-core

解决方案


推荐阅读