LINQ to Entities does not recognize the method 'System.Windows.Forms.DataGridViewCell get_Item(Int32)' method

StackOverflow https://stackoverflow.com/questions/19140270

  •  30-06-2022
  •  | 
  •  

Question

Hi im too new on entity framework and im using it on windows form app.

            using (GezentiEntities GE = new GezentiEntities())
        {
            var cities = from c in GE.Cities
                         where c.CountryId == ((Guid)(dgCountry.SelectedRows[0].Cells[0].Value))
                         select new  { c.Id, Şehir = c.Name };
            dgCity.DataSource = cities.ToList();

        }

on dgCity.DataSource = cities.ToList(); line it gives me error when im using it with where condition and ((Guid)(dgCountry.SelectedRows[0].Cells[0].Value)) that code works fine it gives me ID.

Was it helpful?

Solution

you may try to get the needed ID out of the linq to entities query

var id = (Guid)dgCountry.SelectedRows[0].Cells[0].Value;
var cities = from c in GE.Cities
                         where c.CountryId == id
                         select new  { c.Id, Şehir = c.Name };
            dgCity.DataSource = cities.ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top