You select itemColl with the keyword new , defining an anonymous type ; you cannot use a foreach with an int type. Your current query returns something like IEnumerable<AnonymousType>
Instead, you can:
var itemColl = from p in re.Kategorie where p.Nazwa == category select p.Id_Kat;
This will return an IEnumerable<int> and you can use it in the current foreach loop.
But if you want to use your current request with a choice of an anonymous type, you need to change your foreach loop with an implicit type of var , and since your current request is returning an object of an anonymous type, you can select Id_kat from the object. Sort of.
foreach (var s in itemColl) { Console.WriteLine(s.Id_kat); }
IMO, the second approach is not recommended because you simply return an int type wrapped in an anonymous type. Better if you can modify your request to return an IEnumerable<int>
source share