I have a list of entities and I want to check how many of them are common to some of the properties. So I used a dictionary
List<Letter> allPsukim = await _context.Letter.Where(a => a.OrderId == Order.Id)
.ToListAsync();
foreach (var item in allPsukim)
{
Psukim newPasuk = new Psukim()
{
Book = item.Book,
Pasuk = item.Pasuk,
Perek = item.Perek
};
if (showPsukim.ContainsKey(newPasuk))
{
List<int> newList = showPsukim[newPasuk];
newList.Add(item.Position);
showPsukim[newPasuk] = newList;
}
else
{
List<int> newList = new List<int>() { item.Position };
showPsukim.Add(newPasuk, newList);
}
}
The problem is that the showPsukim.ContainsKey(newPasuk)
always shows that no key exists.
Where can I use entity as a key and check if it exists?