LINQ to Entities无法识别方法'System.Windows.Forms.DataGridViewCell get_Item(Int32)'方法

时间:2013-10-02 15:08:02

标签: linq entities

嗨我在实体框架上太新了,我在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();当我使用where where条件和((Guid)(dgCountry.SelectedRows [0] .Cells [0] .Value))时,它给了我错误,该代码工作得很好,它给了我ID。

1 个答案:

答案 0 :(得分:0)

您可以尝试从linq到实体查询中获取所需的ID

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();