Asp.net core mvc 如何查询数组
首先让我先说,我不知道该如何命名这个问题,对此我深表歉意。如果有什么东西让我或你觉得很聪明,我会编辑它 我的问题是:Asp.net core mvc 如何查询数组,asp.net-core-mvc,entity-framework-core,Asp.net Core Mvc,Entity Framework Core,首先让我先说,我不知道该如何命名这个问题,对此我深表歉意。如果有什么东西让我或你觉得很聪明,我会编辑它 我的问题是: public IActionResult(string deckList //comma-separated-string of numeric characters which represent id's) { var cards = _context.Cards; var deckListArray = deckList.Split(','); foreach (var i
public IActionResult(string deckList //comma-separated-string of numeric characters which represent id's)
{
var cards = _context.Cards;
var deckListArray = deckList.Split(',');
foreach (var id in deckListArray)
{
int x = Convert.ToInt32(id);
cards = cards.Where(c => c.ID == id);
}
好的,所以我知道查询循环内部是不受欢迎的,至少可以说是因为性能问题,但是这个IQueryable集合甚至不能正确地填充此代码
获取阵列中所有id为的卡的适当查询是什么
var ids = decklist.Split( ',' )
.Select( id => Convert.ToInt32( id ) )
.ToArray();
var cards = _context.Cards.Where( c => ids.Contains( c.ID ) );