在函数参数中传递 List<int> 超过 10 个 lac 记录?
Passing List<int> with more then 10 lac records in function parameter?
我的情况是数据库中有超过 10 条 lac 记录。
当用户使用一些选定的记录在 MVC 中点击我的操作方法时,我想通过获取所有记录并将它们与用户传递的记录进行比较来检查这些记录是否存在于数据库中。
然后我想将所有这些记录传递给另一个函数。
在函数参数中传递这么多记录安全吗??
这是一个演示:-
//Action Method
[HttpGet]
Public ActionResult SaveRecords(List<int> selectedRecords)
{
List<int> allRecordsFromDB = _db.GetAllRecords();
if(allRecordsFromDB.Contains(selectedRecords))
{
_Process(allRecordsFromDB); //here I am passing more than 10 lac devices to a function as parameter
}
}
Private void _Process(List<int> allRecords)
{
//Do some process here
}
谢谢:)
是的。因为它是一个列表,所以您只传递对项目列表的引用,而不是实际项目本身。
是的会很安全。
正如菲尔所说 "As it is a list you are only passing a reference to the list of items and not the actual items themselves."
另一种解决方案 是您可以将所有记录放入会话或缓存(根据您的用例)并且可以在任何地方访问..无需将记录作为参数传递.
我的情况是数据库中有超过 10 条 lac 记录。 当用户使用一些选定的记录在 MVC 中点击我的操作方法时,我想通过获取所有记录并将它们与用户传递的记录进行比较来检查这些记录是否存在于数据库中。
然后我想将所有这些记录传递给另一个函数。 在函数参数中传递这么多记录安全吗??
这是一个演示:-
//Action Method
[HttpGet]
Public ActionResult SaveRecords(List<int> selectedRecords)
{
List<int> allRecordsFromDB = _db.GetAllRecords();
if(allRecordsFromDB.Contains(selectedRecords))
{
_Process(allRecordsFromDB); //here I am passing more than 10 lac devices to a function as parameter
}
}
Private void _Process(List<int> allRecords)
{
//Do some process here
}
谢谢:)
是的。因为它是一个列表,所以您只传递对项目列表的引用,而不是实际项目本身。
是的会很安全。
正如菲尔所说 "As it is a list you are only passing a reference to the list of items and not the actual items themselves."
另一种解决方案 是您可以将所有记录放入会话或缓存(根据您的用例)并且可以在任何地方访问..无需将记录作为参数传递.