带有int数组参数的EF ExecuteSqlCommand

 Zan吴磊Leo 发布于 2023-02-11 10:09

尝试使用类型数组int传递参数时遇到问题.到目前为止我做了什么,但两种方法都失败了.

方法1(失败):

int[] CategoryArray;
CategoryArray = new int[userItem.ListItemId.Count()];
int i=0;

foreach (int catID in userItem.ListItemId)
{
    CategoryArray[i] = catID;
    i++;
}

db.Database.ExecuteSqlCommand("delete from SupportRegion where UserId={0} and CategoryID not in ({1})", userItem.UserId, CategoryArray);

方法2(也失败):

db.Database.ExecuteSqlCommand("delete from SupportRegion where UserId={0} and CategoryID not in ({1})", userItem.UserId, String.Join(",", userItem.ListItemId)); 

如何将参数定义为整数数组?

非常感谢

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有