【问题标题】:LINQ to Entities does not recognize the method 'System.Windows.Forms.DataGridViewCell get_Item(Int32)' methodLINQ to Entities 无法识别方法“System.Windows.Forms.DataGridViewCell get_Item(Int32)”方法
【发布时间】:2013-10-02 15:08:01
【问题描述】:

嗨,我在实体框架上太新了,我在 Windows 窗体应用程序上使用它。

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

        }

在 dgCity.DataSource = city.ToList();当我将它与 where 条件和 ((Guid)(dgCountry.SelectedRows[0].Cells[0].Value)) 一起使用时,它给了我错误,该代码工作正常,它给了我 ID。

【问题讨论】:

    标签: linq entities


    【解决方案1】:

    您可以尝试从 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();
    

    【讨论】:

      猜你喜欢
      • 2011-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2017-01-02
      相关资源
      最近更新 更多