0

Please check loop bellow. "BulkScannedItemIds" is an array with few ids which looping to retrieve those products and storing in "singleItems" But problem is "singleItems" is not an array. That's why its not holding all values. So What i want is store all value to a array. Please advice me how can i make this ("singleItems") simple variable to array? So it will able to hold all values after run the loop?

foreach (var BulkScannedItemId in BulkScannedItemIds)
{
    var singleItems = ctx.BulkScannedItems.Where(x => x.UserSellerScanRequestId == id && x.BulkScannedItemId == BulkScannedItemId).ToList();
}
1
  • Just use ToArray() instead of ToList() for having an array. And remove the foreach loop, it does nothing, beside slow your app Commented Aug 2, 2017 at 8:25

1 Answer 1

2

You can do this without the loop using LINQ:

var singleItems = ctx.BulkScannedItems.Where(x => x.UserSellerScanRequestId == id && BulkScannedItemIds.Contains(x.BulkScannedItemId)).ToList()

EDIT: Or if you want an Array call ToArray instead:

var singleItems = ctx.BulkScannedItems.Where(x => x.UserSellerScanRequestId == id && BulkScannedItemIds.Contains(x.BulkScannedItemId)).ToArray()
Sign up to request clarification or add additional context in comments.

1 Comment

Unless you call .ToArray() in which case it will be converted to an array... :O

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.