Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to "where" on strongly typed list, error CS0103

Tags:

c#

join

linq

I've got linq which joins two lists by id and returns strongly typed List:

   List<TestowaKlasaDlaLinq> linqlambda = ListDetailedData.Join(PlacesList, a => a.place.id, b => b.id, (a, b) =>
                new TestowaKlasaDlaLinq()
                {
                    Czas = a.startDate.TimeOfDay.ToString(),
                    Co = a.name,
                    Miasto = b.address.city,
                    Miejsce = a.organizer.designation
                }).ToList();

For now everything works. Problem appeared when I tried to filter that list e.g.:

   var onlyGdansk = linqlambda.Where(x => x.Miasto.Equals("Gdańsk")).Select(x => x).ToList();

That error came out: enter image description here

How is this possible that strongly field of strongly typed List of type "TestowaKlasaDlaLinq" doesnt exist in that context?

like image 897
bc291 Avatar asked Nov 24 '25 18:11

bc291


1 Answers

I think, One of the x.Miasto value is null and that is the reason, it shows you this error.

var onlyGdansk = linqlambda.Where(tkdl => tkdl.Miasto!=null && tkdl.Miasto.Equals("Gdańsk")).Select(dl => dl).ToList(); 
like image 178
Gaurang Dave Avatar answered Nov 27 '25 08:11

Gaurang Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!