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
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top