I use Linq for entities to query the database to get an int list for further processing. I have two ways to get the list as shown below:
First up is:
List<int> lstBizIds = new List<int>() { 1, 2, 3, 4, 5 };
List<int> lstProjectIds = context.Projects.Where(x => lstBizIds.Contains(x.businessId)).Select(x => x.projectId).ToList();
Second:
List<int> lstBizIds = new List<int>() { 1, 2, 3, 4, 5 };
List<int> lstProjectIds = context.Projects.Join(lstBizIds, p => p.businessId, u => u, (p, u) => p.projectId).ToList();
Now my question is: which of the above methods works best? Does it also affect performance if the first ie lstBizIds list grows in size? Suggest me other implementation methods if this is a performance hit.
source
share