I have Inventories table and here I save all ProductId's who is below 10 or the same as 10 in Array
public int[] OrderNow()
{
return context.Inventory.Where(u => u.Quantity <= 10).Select(i =>i.ProductId)
.ToArray();
}
I know I have 3 products that Quantity is below 10 and when I run debug I can see those Ids. So far so good.
But When I want to retrieve names of those products, I just can get one of those 3 products...
To get names of those Products I wrote this code, but it's returning only one Product name.
public string[] ProductName()
{
var prId = OrderNow();
foreach (var p in prId)
{
return context.Products.Where(u => u.ProductId == p)
.Select(p => p.ProductName).ToArray();
// After one loop it's jumping foreach process .. I don't know why
}
return null; // I don't know what to write here, but I must to return something
}
Edited with a similar problem...
public int[] OrderNow()
{
return context.Inventory.Where(u => u.Quantity <= 10).Select(i =>i.DepartmentId)
.ToArray();
}
And my User email
public string[] UserEmails()
{
var departmentIds= OrderNow(); // Gets the array of product ids
return context.Users
.Where(u => u.IsInventoryAdmin == true)
.Where(u => departmentIds.Contains(u.DepartmentId)) // Here failing
.Select(e => e.Email)
.ToArray();
}
returnbreaks out of a method.returnexits your function. And you are already returningstring[]return context.Products.Where(u => prId.Contains(u.ProductId)).Select(p => p.ProductName).ToArray();