2013-10-02 120 views
0

嗨我太新的實體框架和即時通訊使用它在Windows窗體應用程序。LINQ to Entities無法識別方法'System.Windows.Forms.DataGridViewCell get_Item(Int32)'方法

  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();當它使用條件和((Guid)(dgCountry.SelectedRows [0] .Cells [0] .Value))代碼工作正常它給我的ID時,它給了我錯誤。

回答

0

您可以嘗試獲得所需的ID了LINQ到實體查詢

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

太感謝你了。 –

相關問題